Built-In Class Date
The built-in Date class.
Method Attributes | Method Name and Description |
---|---|
format(format)
Converts a date to a string using the specified formatting.
|
|
<static> |
Date.parse(s, format)
Parses a date from a string, optionally using the specified formatting.
|
Converts a date to a string using the specified formatting. If the Date object already supports the toLocaleFormat method, as in Firefox, this is simply an alias to the built-in method.
The format string is in the same format expected by the strftime function in C. The following conversion specifications are supported:
- %a - abbreviated weekday name.
- %A - full weekday name.
- %b - abbreviated month names.
- %B - full month names.
- %c - locale's appropriate date and time.
- %C - century number.
- %d - day of month [01,31] (zero padded).
- %D - same as %m/%d/%y.
- %e - day of month [ 1,31] (space padded).
- %h - same as %b.
- %H - hour (24-hour clock) [00,23] (zero padded).
- %I - hour (12-hour clock) [01,12] (zero padded).
- %m - month number [01,12] (zero padded).
- %M - minute [0,59] (zero padded).
- %n - newline character.
- %p - locale's equivalent of a.m. or p.m.
- %r - same as %I:%M:%S %p.
- %R - same as %H:%M.
- %S - second [00,61] (zero padded).
- %t - tab character.
- %T - same as %H:%M:%S.
- %x - same as %m/%d/%y.
- %X - same as %I:%M:%S %p.
- %y - year with century [00,99] (zero padded).
- %Y - year including century.
- %% - %.
- %j - day number [1,366].
- %u - weekday number [1,7].
- %U - week number [00,53].
- %V - week number [01,53].
- %w - weekday number [0,6].
- %W - week number [00,53].
- %Z - timezone name or abbreviation.
- Parameters:
- {string} format
- a format string.
- Returns:
- {string} the formatted date.
- See:
- Date.toLocaleFormat documentation.
- strftime documentation.
Parses a date from a string, optionally using the specified formatting. If only a single argument is specified (i.e., format is not specified), this method invokes the native implementation to guarantee backwards-compatibility.
The format string is in the same format expected by the strptime function in C. The following conversion specifications are supported:
- %b - abbreviated month names.
- %B - full month names.
- %h - same as %b.
- %d - day of month [1,31].
- %e - same as %d.
- %H - hour (24-hour clock) [0,23].
- %m - month number [1,12].
- %M - minute [0,59].
- %S - second [0,61].
- %y - year with century [0,99].
- %Y - year including century.
- %% - %.
- %a - day of week, either abbreviated or full name.
- %A - same as %a.
- %c - locale's appropriate date and time.
- %C - century number.
- %D - same as %m/%d/%y.
- %I - hour (12-hour clock) [1,12].
- %j - day number [1,366].
- %n - any white space.
- %p - locale's equivalent of a.m. or p.m.
- %r - same as %I:%M:%S %p.
- %R - same as %H:%M.
- %t - same as %n.
- %T - same as %H:%M:%S.
- %U - week number [0,53].
- %w - weekday [0,6].
- %W - week number [0,53].
- %x - locale's equivalent to %m/%d/%y.
- %X - locale's equivalent to %I:%M:%S %p.
- Parameters:
- {string} s
- the string to parse as a date.
- {string} format Optional
- an optional format string.
- Returns:
- {Date} the parsed date.
- See:
- strptime documentation.