21.4 Date Objects
21.4.1 Overview of Date Objects and Definitions of Abstract Operations
The following
21.4.1.1 Time Values and Time Range
Time measurement in ECMAScript is analogous to time measurement in POSIX, in particular sharing definition in terms of the proleptic Gregorian calendar, an epoch of midnight at the beginning of 1 January 1970 UTC, and an accounting of every day as comprising exactly 86,400 seconds (each of which is 1000 milliseconds long).
An ECMAScript time value
Time values do not account for UTC leap seconds—there are no time values representing instants within positive leap seconds, and there are time values representing instants removed from the UTC timeline by negative leap seconds. However, the definition of time values nonetheless yields piecewise alignment with UTC, with discontinuities only at leap second boundaries and zero difference outside of leap seconds.
A Number can exactly represent all
The exact moment of midnight at the beginning of 1 January 1970 UTC is represented by the time value
In the proleptic Gregorian calendar, leap years are precisely those which are both divisible by 4 and either divisible by 400 or not divisible by 100.
The 400 year cycle of the proleptic Gregorian calendar contains 97 leap years. This yields an average of 365.2425 days per year, which is 31,556,952,000 milliseconds. Therefore, the maximum range a Number could represent exactly with millisecond precision is approximately -285,426 to 285,426 years relative to 1970. The smaller range supported by a time value as specified in this section is approximately -273,790 to 273,790 years relative to 1970.
21.4.1.2 Time-related Constants
These constants are referenced by algorithms in the following sections.
21.4.1.3 Day ( t )
The abstract operation Day takes argument t (a
21.4.1.4 TimeWithinDay ( t )
The abstract operation TimeWithinDay takes argument t (a
21.4.1.5 DaysInYear ( y )
The abstract operation DaysInYear takes argument y (an
21.4.1.6 DayFromYear ( y )
The abstract operation DayFromYear takes argument y (an
- Let ry be
ℝ (y). - NOTE: In the following steps, numYears1, numYears4, numYears100, and numYears400 represent the number of years divisible by 1, 4, 100, and 400, respectively, that occur between the
epoch and the start of year y. The number is negative if y is before theepoch . - Let numYears1 be (ry - 1970).
- Let numYears4 be
floor ((ry - 1969) / 4). - Let numYears100 be
floor ((ry - 1901) / 100). - Let numYears400 be
floor ((ry - 1601) / 400). - Return
𝔽 (365 × numYears1 + numYears4 - numYears100 + numYears400).
21.4.1.7 TimeFromYear ( y )
The abstract operation TimeFromYear takes argument y (an
- Return
msPerDay ×DayFromYear (y).
21.4.1.8 YearFromTime ( t )
The abstract operation YearFromTime takes argument t (a
- Return the largest
integral Number y (closest to +∞) such thatTimeFromYear (y) ≤ t.
21.4.1.9 DayWithinYear ( t )
The abstract operation DayWithinYear takes argument t (a
- Return
Day (t) -DayFromYear (YearFromTime (t)).
21.4.1.10 InLeapYear ( t )
The abstract operation InLeapYear takes argument t (a
- If
DaysInYear (YearFromTime (t)) is366 𝔽, return1 𝔽; else return+0 𝔽.
21.4.1.11 MonthFromTime ( t )
The abstract operation MonthFromTime takes argument t (a
- Let inLeapYear be
InLeapYear (t). - Let dayWithinYear be
DayWithinYear (t). - If dayWithinYear <
31 𝔽, return+0 𝔽. - If dayWithinYear <
59 𝔽 + inLeapYear, return1 𝔽. - If dayWithinYear <
90 𝔽 + inLeapYear, return2 𝔽. - If dayWithinYear <
120 𝔽 + inLeapYear, return3 𝔽. - If dayWithinYear <
151 𝔽 + inLeapYear, return4 𝔽. - If dayWithinYear <
181 𝔽 + inLeapYear, return5 𝔽. - If dayWithinYear <
212 𝔽 + inLeapYear, return6 𝔽. - If dayWithinYear <
243 𝔽 + inLeapYear, return7 𝔽. - If dayWithinYear <
273 𝔽 + inLeapYear, return8 𝔽. - If dayWithinYear <
304 𝔽 + inLeapYear, return9 𝔽. - If dayWithinYear <
334 𝔽 + inLeapYear, return10 𝔽. Assert : dayWithinYear <365 𝔽 + inLeapYear.- Return
11 𝔽.
21.4.1.12 DateFromTime ( t )
The abstract operation DateFromTime takes argument t (a
- Let inLeapYear be
InLeapYear (t). - Let dayWithinYear be
DayWithinYear (t). - Let month be
MonthFromTime (t). - If month is
+0 𝔽, return dayWithinYear +1 𝔽. - If month is
1 𝔽, return dayWithinYear -30 𝔽. - If month is
2 𝔽, return dayWithinYear -58 𝔽 - inLeapYear. - If month is
3 𝔽, return dayWithinYear -89 𝔽 - inLeapYear. - If month is
4 𝔽, return dayWithinYear -119 𝔽 - inLeapYear. - If month is
5 𝔽, return dayWithinYear -150 𝔽 - inLeapYear. - If month is
6 𝔽, return dayWithinYear -180 𝔽 - inLeapYear. - If month is
7 𝔽, return dayWithinYear -211 𝔽 - inLeapYear. - If month is
8 𝔽, return dayWithinYear -242 𝔽 - inLeapYear. - If month is
9 𝔽, return dayWithinYear -272 𝔽 - inLeapYear. - If month is
10 𝔽, return dayWithinYear -303 𝔽 - inLeapYear. Assert : month is11 𝔽.- Return dayWithinYear -
333 𝔽 - inLeapYear.
21.4.1.13 WeekDay ( t )
The abstract operation WeekDay takes argument t (a
21.4.1.14 HourFromTime ( t )
The abstract operation HourFromTime takes argument t (a
21.4.1.15 MinFromTime ( t )
The abstract operation MinFromTime takes argument t (a
- Return
𝔽 (floor (ℝ (t /msPerMinute ))modulo MinutesPerHour ).
21.4.1.16 SecFromTime ( t )
The abstract operation SecFromTime takes argument t (a
- Return
𝔽 (floor (ℝ (t /msPerSecond ))modulo SecondsPerMinute ).
21.4.1.17 msFromTime ( t )
The abstract operation msFromTime takes argument t (a
- Return
𝔽 (ℝ (t)modulo ℝ (msPerSecond )).
21.4.1.18 GetUTCEpochNanoseconds ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond )
The abstract operation GetUTCEpochNanoseconds takes arguments year (an
21.4.1.19 Time Zone Identifiers
Time zones in ECMAScript are represented by time zone identifiers, which are Strings composed entirely of code units in the
A primary time zone identifier is the preferred identifier for an available named time zone. A non-primary time zone identifier is an identifier for an available named time zone that is not a primary time zone identifier. An available named time zone identifier is either a primary time zone identifier or a non-primary time zone identifier. Each available named time zone identifier is associated with exactly one available named time zone. Each available named time zone is associated with exactly one primary time zone identifier and zero or more non-primary time zone identifiers.
ECMAScript implementations must support an available named time zone with the identifier
Implementations that follow the requirements for time zones as described in the ECMA-402 Internationalization API specification are called time zone aware.
Time zone aware implementations must support available named time zones corresponding to the Zone and Link names of the IANA Time Zone Database, and only such names.
In time zone aware implementations, a primary time zone identifier is a Zone name, and a non-primary time zone identifier is a Link name, respectively, in the IANA Time Zone Database except as specifically overridden by
21.4.1.20 GetNamedTimeZoneEpochNanoseconds ( timeZoneIdentifier, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond )
The
When the input represents a local time occurring more than once because of a negative time zone transition (e.g. when daylight saving time ends or the time zone offset is decreased due to a time zone rule change), the returned
The default implementation of GetNamedTimeZoneEpochNanoseconds, to be used for ECMAScript implementations that do not include local political rules for any time zones, performs the following steps when called:
Assert : timeZoneIdentifier is"UTC" .- Let epochNanoseconds be
GetUTCEpochNanoseconds (year, month, day, hour, minute, second, millisecond, microsecond, nanosecond). - Return « epochNanoseconds ».
It is required for
1:30 AM on 5 November 2017 in America/New_York is repeated twice, so GetNamedTimeZoneEpochNanoseconds(
2:30 AM on 12 March 2017 in America/New_York does not exist, so GetNamedTimeZoneEpochNanoseconds(
21.4.1.21 GetNamedTimeZoneOffsetNanoseconds ( timeZoneIdentifier, epochNanoseconds )
The
The returned
The default implementation of GetNamedTimeZoneOffsetNanoseconds, to be used for ECMAScript implementations that do not include local political rules for any time zones, performs the following steps when called:
Assert : timeZoneIdentifier is"UTC" .- Return 0.
Time zone offset values may be positive or negative.
21.4.1.22 Time Zone Identifier Record
A Time Zone Identifier Record is a
Time Zone Identifier Records have the fields listed in
Field Name | Value | Meaning |
---|---|---|
[[Identifier]] | a String | An |
[[PrimaryIdentifier]] | a String | The |
If [[Identifier]] is a
21.4.1.23 AvailableNamedTimeZoneIdentifiers ( )
The
- If the implementation does not include local political rules for any time zones, then
- Return « the
Time Zone Identifier Record { [[Identifier]]:"UTC" , [[PrimaryIdentifier]]:"UTC" } ».
- Return « the
- Let identifiers be the
List of uniqueavailable named time zone identifiers . - Sort identifiers into the same order as if an Array of the same values had been sorted using %Array.prototype.sort% with
undefined as comparefn. - Let result be a new empty
List . - For each element identifier of identifiers, do
- Let primary be identifier.
- If identifier is a
non-primary time zone identifier in this implementation and identifier is not"UTC" , then- Set primary to the
primary time zone identifier associated with identifier. - NOTE: An implementation may need to resolve identifier iteratively to obtain the
primary time zone identifier .
- Set primary to the
- Let record be the
Time Zone Identifier Record { [[Identifier]]: identifier, [[PrimaryIdentifier]]: primary }. - Append record to result.
Assert : result contains aTime Zone Identifier Record r such that r.[[Identifier]] is"UTC" and r.[[PrimaryIdentifier]] is"UTC" .- Return result.
21.4.1.24 SystemTimeZoneIdentifier ( )
The
- If the implementation only supports the UTC time zone, return
"UTC" . - Let systemTimeZoneString be the String representing the
host environment 's current time zone, either aprimary time zone identifier or anoffset time zone identifier. - Return systemTimeZoneString.
To ensure the level of functionality that implementations commonly provide in the methods of the Date object, it is recommended that SystemTimeZoneIdentifier return an IANA time zone name corresponding to the
For example, if the
21.4.1.25 LocalTime ( t )
The abstract operation LocalTime takes argument t (a
- Let systemTimeZoneIdentifier be
SystemTimeZoneIdentifier (). - If
IsTimeZoneOffsetString (systemTimeZoneIdentifier) istrue , then- Let offsetNs be
ParseTimeZoneOffsetString (systemTimeZoneIdentifier).
- Let offsetNs be
- Else,
- Let offsetNs be
GetNamedTimeZoneOffsetNanoseconds (systemTimeZoneIdentifier,ℤ (ℝ (t) × 106)).
- Let offsetNs be
- Let offsetMs be
truncate (offsetNs / 106). - Return t +
𝔽 (offsetMs).
If political rules for the local time t are not available within the implementation, the result is t because
It is required for
Two different input
21.4.1.26 UTC ( t )
The abstract operation UTC takes argument t (a Number) and returns a
- If t is not
finite , returnNaN . - Let systemTimeZoneIdentifier be
SystemTimeZoneIdentifier (). - If
IsTimeZoneOffsetString (systemTimeZoneIdentifier) istrue , then- Let offsetNs be
ParseTimeZoneOffsetString (systemTimeZoneIdentifier).
- Let offsetNs be
- Else,
- Let possibleInstants be
GetNamedTimeZoneEpochNanoseconds (systemTimeZoneIdentifier,ℝ (YearFromTime (t)),ℝ (MonthFromTime (t)) + 1,ℝ (DateFromTime (t)),ℝ (HourFromTime (t)),ℝ (MinFromTime (t)),ℝ (SecFromTime (t)),ℝ (msFromTime (t)), 0, 0). - NOTE: The following steps ensure that when t represents local time repeating multiple times at a negative time zone transition (e.g. when the daylight saving time ends or the time zone offset is decreased due to a time zone rule change) or skipped local time at a positive time zone transition (e.g. when the daylight saving time starts or the time zone offset is increased due to a time zone rule change), t is interpreted using the time zone offset before the transition.
- If possibleInstants is not empty, then
- Let disambiguatedInstant be possibleInstants[0].
- Else,
- NOTE: t represents a local time skipped at a positive time zone transition (e.g. due to daylight saving time starting or a time zone rule change increasing the UTC offset).
- Let possibleInstantsBefore be
GetNamedTimeZoneEpochNanoseconds (systemTimeZoneIdentifier,ℝ (YearFromTime (tBefore)),ℝ (MonthFromTime (tBefore)) + 1,ℝ (DateFromTime (tBefore)),ℝ (HourFromTime (tBefore)),ℝ (MinFromTime (tBefore)),ℝ (SecFromTime (tBefore)),ℝ (msFromTime (tBefore)), 0, 0), where tBefore is the largestintegral Number < t for which possibleInstantsBefore is not empty (i.e., tBefore represents the last local time before the transition). - Let disambiguatedInstant be the last element of possibleInstantsBefore.
- Let offsetNs be
GetNamedTimeZoneOffsetNanoseconds (systemTimeZoneIdentifier, disambiguatedInstant).
- Let possibleInstants be
- Let offsetMs be
truncate (offsetNs / 106). - Return t -
𝔽 (offsetMs).
Input t is nominally a
If political rules for the local time t are not available within the implementation, the result is t because
It is required for
1:30 AM on 5 November 2017 in America/New_York is repeated twice (fall backward), but it must be interpreted as 1:30 AM UTC-04 instead of 1:30 AM UTC-05.
In UTC(
2:30 AM on 12 March 2017 in America/New_York does not exist, but it must be interpreted as 2:30 AM UTC-05 (equivalent to 3:30 AM UTC-04).
In UTC(
21.4.1.27 MakeTime ( hour, min, sec, ms )
The abstract operation MakeTime takes arguments hour (a Number), min (a Number), sec (a Number), and ms (a Number) and returns a Number. It calculates a number of milliseconds. It performs the following steps when called:
- If hour is not
finite , min is notfinite , sec is notfinite , or ms is notfinite , returnNaN . - Let h be
𝔽 (!ToIntegerOrInfinity (hour)). - Let m be
𝔽 (!ToIntegerOrInfinity (min)). - Let s be
𝔽 (!ToIntegerOrInfinity (sec)). - Let milli be
𝔽 (!ToIntegerOrInfinity (ms)). - Return ((h ×
msPerHour + m ×msPerMinute ) + s ×msPerSecond ) + milli.
The arithmetic in MakeTime is floating-point arithmetic, which is not associative, so the operations must be performed in the correct order.
21.4.1.28 MakeDay ( year, month, date )
The abstract operation MakeDay takes arguments year (a Number), month (a Number), and date (a Number) and returns a Number. It calculates a number of days. It performs the following steps when called:
- If year is not
finite , month is notfinite , or date is notfinite , returnNaN . - Let y be
𝔽 (!ToIntegerOrInfinity (year)). - Let m be
𝔽 (!ToIntegerOrInfinity (month)). - Let dt be
𝔽 (!ToIntegerOrInfinity (date)). - Let ym be y +
𝔽 (floor (ℝ (m) / 12)). - If ym is not
finite , returnNaN . - Let mn be
𝔽 (ℝ (m)modulo 12). - Find a
finite time value t such thatYearFromTime (t) is ym,MonthFromTime (t) is mn, andDateFromTime (t) is1 𝔽; but if this is not possible (because some argument is out of range), returnNaN . - Return
Day (t) + dt -1 𝔽.
21.4.1.29 MakeDate ( day, time )
The abstract operation MakeDate takes arguments day (a Number) and time (a Number) and returns a Number. It calculates a number of milliseconds. It performs the following steps when called:
21.4.1.30 MakeFullYear ( year )
The abstract operation MakeFullYear takes argument year (a Number) and returns an
- If year is
NaN , returnNaN . - Let truncated be !
ToIntegerOrInfinity (year). - If truncated is in the
inclusive interval from 0 to 99, return1900 𝔽 +𝔽 (truncated). - Return
𝔽 (truncated).
21.4.1.31 TimeClip ( time )
The abstract operation TimeClip takes argument time (a Number) and returns a Number. It calculates a number of milliseconds. It performs the following steps when called:
- If time is not
finite , returnNaN . - If
abs (ℝ (time)) > 8.64 × 1015, returnNaN . - Return
𝔽 (!ToIntegerOrInfinity (time)).
21.4.1.32 Date Time String Format
ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 calendar date extended format. The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ
Where the elements are as follows:
YYYY
|
is the year in the proleptic Gregorian calendar as four decimal digits from 0000 to 9999, or as an |
-
|
|
MM
|
is the month of the year as two decimal digits from 01 (January) to 12 (December). |
DD
|
is the day of the month as two decimal digits from 01 to 31. |
T
|
|
HH
|
is the number of complete hours that have passed since midnight as two decimal digits from 00 to 24. |
:
|
|
mm
|
is the number of complete minutes since the start of the hour as two decimal digits from 00 to 59. |
ss
|
is the number of complete seconds since the start of the minute as two decimal digits from 00 to 59. |
.
|
|
sss
|
is the number of complete milliseconds since the start of the second as three decimal digits. |
Z
|
is the UTC offset representation specified as HH:mm (a subset of the |
This format includes date-only forms:
YYYY YYYY-MM YYYY-MM-DD
It also includes “date-time” forms that consist of one of the above date-only forms immediately followed by one of the following time forms with an optional UTC offset representation appended:
THH:mm THH:mm:ss THH:mm:ss.sss
A string containing out-of-bounds or nonconforming elements is not a valid instance of this format.
As every day both starts and ends with midnight, the two notations 00:00
and 24:00
are available to distinguish the two midnights that can be associated with one date. This means that the following two notations refer to exactly the same point in time: 1995-02-04T24:00
and 1995-02-05T00:00
. This interpretation of the latter form as "end of a calendar day" is consistent with ISO 8601, even though that specification reserves it for describing time intervals and does not permit it within representations of single points in time.
There exists no international standard that specifies abbreviations for civil time zones like CET, EST, etc. and sometimes the same abbreviation is even used for two very different time zones. For this reason, both ISO 8601 and this format specify numeric representations of time zone offsets.
21.4.1.32.1 Expanded Years
Covering the full Date.parse
Examples of date-
-271821-04-20T00:00:00Z | 271822 B.C. |
-000001-01-01T00:00:00Z | 2 B.C. |
+000000-01-01T00:00:00Z | 1 B.C. |
+000001-01-01T00:00:00Z | 1 A.D. |
+001970-01-01T00:00:00Z | 1970 A.D. |
+002009-12-15T00:00:00Z | 2009 A.D. |
+275760-09-13T00:00:00Z | 275760 A.D. |
21.4.1.33 Time Zone Offset String Format
ECMAScript defines a string interchange format for UTC offsets, derived from ISO 8601.
The format is described by the following grammar.
The usage of Unicode code points in this grammar is listed in
Code Point | Unicode Name | Abbreviation |
---|---|---|
U+2212
|
MINUS SIGN | <MINUS> |
Syntax
21.4.1.33.1 IsTimeZoneOffsetString ( offsetString )
The abstract operation IsTimeZoneOffsetString takes argument offsetString (a String) and returns a Boolean. The return value indicates whether offsetString conforms to the grammar given by
- Let parseResult be
ParseText (StringToCodePoints (offsetString),UTCOffset ). - If parseResult is a
List of errors, returnfalse . - Return
true .
21.4.1.33.2 ParseTimeZoneOffsetString ( offsetString )
The abstract operation ParseTimeZoneOffsetString takes argument offsetString (a String) and returns an
- Let parseResult be
ParseText (StringToCodePoints (offsetString),UTCOffset ). Assert : parseResult is not aList of errors.Assert : parseResult contains aTemporalSign Parse Node .- Let parsedSign be the
source text matched by theTemporalSign Parse Node contained within parseResult. - If parsedSign is the single code point U+002D (HYPHEN-MINUS) or U+2212 (MINUS SIGN), then
- Let sign be -1.
- Else,
- Let sign be 1.
- NOTE: Applications of
StringToNumber below do not lose precision, since each of the parsed values is guaranteed to be a sufficiently short string of decimal digits. Assert : parseResult contains anHour Parse Node .- Let parsedHours be the
source text matched by theHour Parse Node contained within parseResult. - Let hours be
ℝ (StringToNumber (CodePointsToString (parsedHours))). - If parseResult does not contain a
MinuteSecond Parse Node , then- Let minutes be 0.
- Else,
- Let parsedMinutes be the
source text matched by the firstMinuteSecond Parse Node contained within parseResult. - Let minutes be
ℝ (StringToNumber (CodePointsToString (parsedMinutes))).
- Let parsedMinutes be the
- If parseResult does not contain two
MinuteSecond Parse Nodes , then- Let seconds be 0.
- Else,
- Let parsedSeconds be the
source text matched by the secondMinuteSecond Parse Node contained within parseResult. - Let seconds be
ℝ (StringToNumber (CodePointsToString (parsedSeconds))).
- Let parsedSeconds be the
- If parseResult does not contain a
TemporalDecimalFraction Parse Node , then- Let nanoseconds be 0.
- Else,
- Let parsedFraction be the
source text matched by theTemporalDecimalFraction Parse Node contained within parseResult. - Let fraction be the
string-concatenation ofCodePointsToString (parsedFraction) and"000000000" . - Let nanosecondsString be the
substring of fraction from 1 to 10. - Let nanoseconds be
ℝ (StringToNumber (nanosecondsString)).
- Let parsedFraction be the
- Return sign × (((hours × 60 + minutes) × 60 + seconds) × 109 + nanoseconds).
21.4.2 The Date Constructor
The Date
- is %Date%.
- is the initial value of the
"Date" property of theglobal object . - creates and initializes a new Date when called as a
constructor . - returns a String representing the current time (UTC) when called as a function rather than as a
constructor . - is a function whose behaviour differs based upon the number and types of its arguments.
- may be used as the value of an
extends
clause of a class definition. Subclassconstructors that intend to inherit the specified Date behaviour must include asuper
call to the Dateconstructor to create and initialize the subclass instance with a [[DateValue]] internal slot.
21.4.2.1 Date ( ...values )
This function performs the following steps when called:
- If NewTarget is
undefined , then- Let now be the
time value (UTC) identifying the current time. - Return
ToDateString (now).
- Let now be the
- Let numberOfArgs be the number of elements in values.
- If numberOfArgs = 0, then
- Let dv be the
time value (UTC) identifying the current time.
- Let dv be the
- Else if numberOfArgs = 1, then
- Let value be values[0].
- If value
is an Object and value has a [[DateValue]] internal slot, then- Let tv be value.[[DateValue]].
- Else,
- Let v be ?
ToPrimitive (value). - If v
is a String , thenAssert : The next step never returns anabrupt completion because vis a String .- Let tv be the result of parsing v as a date, in exactly the same manner as for the
parse
method (21.4.3.2 ).
- Else,
- Let tv be ?
ToNumber (v).
- Let tv be ?
- Let v be ?
- Let dv be
TimeClip (tv).
- Else,
Assert : numberOfArgs ≥ 2.- Let y be ?
ToNumber (values[0]). - Let m be ?
ToNumber (values[1]). - If numberOfArgs > 2, let dt be ?
ToNumber (values[2]); else let dt be1 𝔽. - If numberOfArgs > 3, let h be ?
ToNumber (values[3]); else let h be+0 𝔽. - If numberOfArgs > 4, let min be ?
ToNumber (values[4]); else let min be+0 𝔽. - If numberOfArgs > 5, let s be ?
ToNumber (values[5]); else let s be+0 𝔽. - If numberOfArgs > 6, let milli be ?
ToNumber (values[6]); else let milli be+0 𝔽. - Let yr be
MakeFullYear (y). - Let finalDate be
MakeDate (MakeDay (yr, m, dt),MakeTime (h, min, s, milli)). - Let dv be
TimeClip (UTC (finalDate)).
- Let O be ?
OrdinaryCreateFromConstructor (NewTarget,"%Date.prototype%" , « [[DateValue]] »). - Set O.[[DateValue]] to dv.
- Return O.
21.4.3 Properties of the Date Constructor
The Date
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has a
"length" property whose value is7 𝔽. - has the following properties:
21.4.3.1 Date.now ( )
This function returns the
21.4.3.2 Date.parse ( string )
This function applies the
If the String conforms to the MM
or DD
elements are absent, HH
, mm
, or ss
elements are absent, sss
element is absent,
If x
is any Date whose milliseconds amount is zero within a particular implementation of ECMAScript, then all of the following expressions should produce the same numeric value in that implementation, if all the properties referenced have their initial values:
x.valueOf()
Date.parse(x.toString())
Date.parse(x.toUTCString())
Date.parse(x.toISOString())
However, the expression
Date.parse(x.toLocaleString())
is not required to produce the same Number value as the preceding three expressions and, in general, the value produced by this function is toString
or toUTCString
method.
21.4.3.3 Date.prototype
The initial value of Date.prototype
is the
This property has the attributes { [[Writable]]:
21.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] )
This function performs the following steps when called:
- Let y be ?
ToNumber (year). - If month is present, let m be ?
ToNumber (month); else let m be+0 𝔽. - If date is present, let dt be ?
ToNumber (date); else let dt be1 𝔽. - If hours is present, let h be ?
ToNumber (hours); else let h be+0 𝔽. - If minutes is present, let min be ?
ToNumber (minutes); else let min be+0 𝔽. - If seconds is present, let s be ?
ToNumber (seconds); else let s be+0 𝔽. - If ms is present, let milli be ?
ToNumber (ms); else let milli be+0 𝔽. - Let yr be
MakeFullYear (y). - Return
TimeClip (MakeDate (MakeDay (yr, m, dt),MakeTime (h, min, s, milli))).
The
This function differs from the Date
21.4.4 Properties of the Date Prototype Object
The Date prototype object:
- is %Date.prototype%.
- is itself an
ordinary object . - is not a Date instance and does not have a [[DateValue]] internal slot.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
Unless explicitly defined otherwise, the methods of the Date prototype object defined below are not generic and the
21.4.4.1 Date.prototype.constructor
The initial value of Date.prototype.constructor
is
21.4.4.2 Date.prototype.getDate ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
DateFromTime (LocalTime (t)).
21.4.4.3 Date.prototype.getDay ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
WeekDay (LocalTime (t)).
21.4.4.4 Date.prototype.getFullYear ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
YearFromTime (LocalTime (t)).
21.4.4.5 Date.prototype.getHours ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
HourFromTime (LocalTime (t)).
21.4.4.6 Date.prototype.getMilliseconds ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
msFromTime (LocalTime (t)).
21.4.4.7 Date.prototype.getMinutes ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
MinFromTime (LocalTime (t)).
21.4.4.8 Date.prototype.getMonth ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
MonthFromTime (LocalTime (t)).
21.4.4.9 Date.prototype.getSeconds ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
SecFromTime (LocalTime (t)).
21.4.4.10 Date.prototype.getTime ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Return dateObject.[[DateValue]].
21.4.4.11 Date.prototype.getTimezoneOffset ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return (t -
LocalTime (t)) /msPerMinute .
21.4.4.12 Date.prototype.getUTCDate ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
DateFromTime (t).
21.4.4.13 Date.prototype.getUTCDay ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
WeekDay (t).
21.4.4.14 Date.prototype.getUTCFullYear ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
YearFromTime (t).
21.4.4.15 Date.prototype.getUTCHours ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
HourFromTime (t).
21.4.4.16 Date.prototype.getUTCMilliseconds ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
msFromTime (t).
21.4.4.17 Date.prototype.getUTCMinutes ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
MinFromTime (t).
21.4.4.18 Date.prototype.getUTCMonth ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
MonthFromTime (t).
21.4.4.19 Date.prototype.getUTCSeconds ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
SecFromTime (t).
21.4.4.20 Date.prototype.setDate ( date )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let dt be ?
ToNumber (date). - If t is
NaN , returnNaN . - Set t to
LocalTime (t). - Let newDate be
MakeDate (MakeDay (YearFromTime (t),MonthFromTime (t), dt),TimeWithinDay (t)). - Let u be
TimeClip (UTC (newDate)). - Set dateObject.[[DateValue]] to u.
- Return u.
21.4.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let y be ?
ToNumber (year). - If t is
NaN , set t to+0 𝔽; otherwise, set t toLocalTime (t). - If month is not present, let m be
MonthFromTime (t); otherwise, let m be ?ToNumber (month). - If date is not present, let dt be
DateFromTime (t); otherwise, let dt be ?ToNumber (date). - Let newDate be
MakeDate (MakeDay (y, m, dt),TimeWithinDay (t)). - Let u be
TimeClip (UTC (newDate)). - Set dateObject.[[DateValue]] to u.
- Return u.
The
If month is not present, this method behaves as if month was present with the value getMonth()
. If date is not present, it behaves as if date was present with the value getDate()
.
21.4.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let h be ?
ToNumber (hour). - If min is present, let m be ?
ToNumber (min). - If sec is present, let s be ?
ToNumber (sec). - If ms is present, let milli be ?
ToNumber (ms). - If t is
NaN , returnNaN . - Set t to
LocalTime (t). - If min is not present, let m be
MinFromTime (t). - If sec is not present, let s be
SecFromTime (t). - If ms is not present, let milli be
msFromTime (t). - Let date be
MakeDate (Day (t),MakeTime (h, m, s, milli)). - Let u be
TimeClip (UTC (date)). - Set dateObject.[[DateValue]] to u.
- Return u.
The
If min is not present, this method behaves as if min was present with the value getMinutes()
. If sec is not present, it behaves as if sec was present with the value getSeconds()
. If ms is not present, it behaves as if ms was present with the value getMilliseconds()
.
21.4.4.23 Date.prototype.setMilliseconds ( ms )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Set ms to ?
ToNumber (ms). - If t is
NaN , returnNaN . - Set t to
LocalTime (t). - Let time be
MakeTime (HourFromTime (t),MinFromTime (t),SecFromTime (t), ms). - Let u be
TimeClip (UTC (MakeDate (Day (t), time))). - Set dateObject.[[DateValue]] to u.
- Return u.
21.4.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let m be ?
ToNumber (min). - If sec is present, let s be ?
ToNumber (sec). - If ms is present, let milli be ?
ToNumber (ms). - If t is
NaN , returnNaN . - Set t to
LocalTime (t). - If sec is not present, let s be
SecFromTime (t). - If ms is not present, let milli be
msFromTime (t). - Let date be
MakeDate (Day (t),MakeTime (HourFromTime (t), m, s, milli)). - Let u be
TimeClip (UTC (date)). - Set dateObject.[[DateValue]] to u.
- Return u.
The
If sec is not present, this method behaves as if sec was present with the value getSeconds()
. If ms is not present, this behaves as if ms was present with the value getMilliseconds()
.
21.4.4.25 Date.prototype.setMonth ( month [ , date ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let m be ?
ToNumber (month). - If date is present, let dt be ?
ToNumber (date). - If t is
NaN , returnNaN . - Set t to
LocalTime (t). - If date is not present, let dt be
DateFromTime (t). - Let newDate be
MakeDate (MakeDay (YearFromTime (t), m, dt),TimeWithinDay (t)). - Let u be
TimeClip (UTC (newDate)). - Set dateObject.[[DateValue]] to u.
- Return u.
The
If date is not present, this method behaves as if date was present with the value getDate()
.
21.4.4.26 Date.prototype.setSeconds ( sec [ , ms ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let s be ?
ToNumber (sec). - If ms is present, let milli be ?
ToNumber (ms). - If t is
NaN , returnNaN . - Set t to
LocalTime (t). - If ms is not present, let milli be
msFromTime (t). - Let date be
MakeDate (Day (t),MakeTime (HourFromTime (t),MinFromTime (t), s, milli)). - Let u be
TimeClip (UTC (date)). - Set dateObject.[[DateValue]] to u.
- Return u.
The
If ms is not present, this method behaves as if ms was present with the value getMilliseconds()
.
21.4.4.27 Date.prototype.setTime ( time )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be ?
ToNumber (time). - Let v be
TimeClip (t). - Set dateObject.[[DateValue]] to v.
- Return v.
21.4.4.28 Date.prototype.setUTCDate ( date )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let dt be ?
ToNumber (date). - If t is
NaN , returnNaN . - Let newDate be
MakeDate (MakeDay (YearFromTime (t),MonthFromTime (t), dt),TimeWithinDay (t)). - Let v be
TimeClip (newDate). - Set dateObject.[[DateValue]] to v.
- Return v.
21.4.4.29 Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , set t to+0 𝔽. - Let y be ?
ToNumber (year). - If month is not present, let m be
MonthFromTime (t); otherwise, let m be ?ToNumber (month). - If date is not present, let dt be
DateFromTime (t); otherwise, let dt be ?ToNumber (date). - Let newDate be
MakeDate (MakeDay (y, m, dt),TimeWithinDay (t)). - Let v be
TimeClip (newDate). - Set dateObject.[[DateValue]] to v.
- Return v.
The
If month is not present, this method behaves as if month was present with the value getUTCMonth()
. If date is not present, it behaves as if date was present with the value getUTCDate()
.
21.4.4.30 Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let h be ?
ToNumber (hour). - If min is present, let m be ?
ToNumber (min). - If sec is present, let s be ?
ToNumber (sec). - If ms is present, let milli be ?
ToNumber (ms). - If t is
NaN , returnNaN . - If min is not present, let m be
MinFromTime (t). - If sec is not present, let s be
SecFromTime (t). - If ms is not present, let milli be
msFromTime (t). - Let date be
MakeDate (Day (t),MakeTime (h, m, s, milli)). - Let v be
TimeClip (date). - Set dateObject.[[DateValue]] to v.
- Return v.
The
If min is not present, this method behaves as if min was present with the value getUTCMinutes()
. If sec is not present, it behaves as if sec was present with the value getUTCSeconds()
. If ms is not present, it behaves as if ms was present with the value getUTCMilliseconds()
.
21.4.4.31 Date.prototype.setUTCMilliseconds ( ms )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Set ms to ?
ToNumber (ms). - If t is
NaN , returnNaN . - Let time be
MakeTime (HourFromTime (t),MinFromTime (t),SecFromTime (t), ms). - Let v be
TimeClip (MakeDate (Day (t), time)). - Set dateObject.[[DateValue]] to v.
- Return v.
21.4.4.32 Date.prototype.setUTCMinutes ( min [ , sec [ , ms ] ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let m be ?
ToNumber (min). - If sec is present, let s be ?
ToNumber (sec). - If ms is present, let milli be ?
ToNumber (ms). - If t is
NaN , returnNaN . - If sec is not present, let s be
SecFromTime (t). - If ms is not present, let milli be
msFromTime (t). - Let date be
MakeDate (Day (t),MakeTime (HourFromTime (t), m, s, milli)). - Let v be
TimeClip (date). - Set dateObject.[[DateValue]] to v.
- Return v.
The
If sec is not present, this method behaves as if sec was present with the value getUTCSeconds()
. If ms is not present, it behaves as if ms was present with the value return by getUTCMilliseconds()
.
21.4.4.33 Date.prototype.setUTCMonth ( month [ , date ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let m be ?
ToNumber (month). - If date is present, let dt be ?
ToNumber (date). - If t is
NaN , returnNaN . - If date is not present, let dt be
DateFromTime (t). - Let newDate be
MakeDate (MakeDay (YearFromTime (t), m, dt),TimeWithinDay (t)). - Let v be
TimeClip (newDate). - Set dateObject.[[DateValue]] to v.
- Return v.
The
If date is not present, this method behaves as if date was present with the value getUTCDate()
.
21.4.4.34 Date.prototype.setUTCSeconds ( sec [ , ms ] )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let s be ?
ToNumber (sec). - If ms is present, let milli be ?
ToNumber (ms). - If t is
NaN , returnNaN . - If ms is not present, let milli be
msFromTime (t). - Let date be
MakeDate (Day (t),MakeTime (HourFromTime (t),MinFromTime (t), s, milli)). - Let v be
TimeClip (date). - Set dateObject.[[DateValue]] to v.
- Return v.
The
If ms is not present, this method behaves as if ms was present with the value getUTCMilliseconds()
.
21.4.4.35 Date.prototype.toDateString ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let tv be dateObject.[[DateValue]].
- If tv is
NaN , return"Invalid Date" . - Let t be
LocalTime (tv). - Return
DateString (t).
21.4.4.36 Date.prototype.toISOString ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let tv be dateObject.[[DateValue]].
- If tv is not
finite , throw aRangeError exception. - If tv corresponds with a year that cannot be represented in the
Date Time String Format , throw aRangeError exception. - Return a String representation of tv in the
Date Time String Format on the UTC time scale, including all format elements and the UTC offset representation"Z" .
21.4.4.37 Date.prototype.toJSON ( key )
This method provides a String representation of a Date for use by JSON.stringify
(
It performs the following steps when called:
- Let O be ?
ToObject (this value). - Let tv be ?
ToPrimitive (O,number ). - If tv
is a Number and tv is notfinite , returnnull . - Return ?
Invoke (O,"toISOString" ).
The argument is ignored.
This method is intentionally generic; it does not require that its toISOString
method.
21.4.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] )
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:
This method returns a String value. The contents of the String are
The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.
21.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:
This method returns a String value. The contents of the String are
The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.
21.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] )
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:
This method returns a String value. The contents of the String are
The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.
21.4.4.41 Date.prototype.toString ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let tv be dateObject.[[DateValue]].
- Return
ToDateString (tv).
For any Date d
such that d.[[DateValue]]
is evenly divisible by 1000, the result of Date.parse(d.toString())
= d.valueOf()
. See
This method is not generic; it throws a
21.4.4.41.1 TimeString ( tv )
The abstract operation TimeString takes argument tv (a Number, but not
- Let hour be
ToZeroPaddedDecimalString (ℝ (HourFromTime (tv)), 2). - Let minute be
ToZeroPaddedDecimalString (ℝ (MinFromTime (tv)), 2). - Let second be
ToZeroPaddedDecimalString (ℝ (SecFromTime (tv)), 2). - Return the
string-concatenation of hour,":" , minute,":" , second, the code unit 0x0020 (SPACE), and"GMT" .
21.4.4.41.2 DateString ( tv )
The abstract operation DateString takes argument tv (a Number, but not
- Let weekday be the Name of the entry in
Table 63 with the NumberWeekDay (tv). - Let month be the Name of the entry in
Table 64 with the NumberMonthFromTime (tv). - Let day be
ToZeroPaddedDecimalString (ℝ (DateFromTime (tv)), 2). - Let yv be
YearFromTime (tv). - If yv is
+0 𝔽 or yv >+0 𝔽, let yearSign be the empty String; otherwise, let yearSign be"-" . - Let paddedYear be
ToZeroPaddedDecimalString (abs (ℝ (yv)), 4). - Return the
string-concatenation of weekday, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE), day, the code unit 0x0020 (SPACE), yearSign, and paddedYear.
Number | Name |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Number | Name |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21.4.4.41.3 TimeZoneString ( tv )
The abstract operation TimeZoneString takes argument tv (an
- Let systemTimeZoneIdentifier be
SystemTimeZoneIdentifier (). - If
IsTimeZoneOffsetString (systemTimeZoneIdentifier) istrue , then- Let offsetNs be
ParseTimeZoneOffsetString (systemTimeZoneIdentifier).
- Let offsetNs be
- Else,
- Let offsetNs be
GetNamedTimeZoneOffsetNanoseconds (systemTimeZoneIdentifier,ℤ (ℝ (tv) × 106)).
- Let offsetNs be
- Let offset be
𝔽 (truncate (offsetNs / 106)). - If offset is
+0 𝔽 or offset >+0 𝔽, then- Let offsetSign be
"+" . - Let absOffset be offset.
- Let offsetSign be
- Else,
- Let offsetSign be
"-" . - Let absOffset be -offset.
- Let offsetSign be
- Let offsetMin be
ToZeroPaddedDecimalString (ℝ (MinFromTime (absOffset)), 2). - Let offsetHour be
ToZeroPaddedDecimalString (ℝ (HourFromTime (absOffset)), 2). - Let tzName be an
implementation-defined string that is either the empty String or thestring-concatenation of the code unit 0x0020 (SPACE), the code unit 0x0028 (LEFT PARENTHESIS), animplementation-defined timezone name, and the code unit 0x0029 (RIGHT PARENTHESIS). - Return the
string-concatenation of offsetSign, offsetHour, offsetMin, and tzName.
21.4.4.41.4 ToDateString ( tv )
The abstract operation ToDateString takes argument tv (an
- If tv is
NaN , return"Invalid Date" . - Let t be
LocalTime (tv). - Return the
string-concatenation ofDateString (t), the code unit 0x0020 (SPACE),TimeString (t), andTimeZoneString (tv).
21.4.4.42 Date.prototype.toTimeString ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let tv be dateObject.[[DateValue]].
- If tv is
NaN , return"Invalid Date" . - Let t be
LocalTime (tv). - Return the
string-concatenation ofTimeString (t) andTimeZoneString (tv).
21.4.4.43 Date.prototype.toUTCString ( )
This method returns a String value representing the instant in time corresponding to the
It performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let tv be dateObject.[[DateValue]].
- If tv is
NaN , return"Invalid Date" . - Let weekday be the Name of the entry in
Table 63 with the NumberWeekDay (tv). - Let month be the Name of the entry in
Table 64 with the NumberMonthFromTime (tv). - Let day be
ToZeroPaddedDecimalString (ℝ (DateFromTime (tv)), 2). - Let yv be
YearFromTime (tv). - If yv is
+0 𝔽 or yv >+0 𝔽, let yearSign be the empty String; otherwise, let yearSign be"-" . - Let paddedYear be
ToZeroPaddedDecimalString (abs (ℝ (yv)), 4). - Return the
string-concatenation of weekday,"," , the code unit 0x0020 (SPACE), day, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE), yearSign, paddedYear, the code unit 0x0020 (SPACE), andTimeString (tv).
21.4.4.44 Date.prototype.valueOf ( )
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Return dateObject.[[DateValue]].
21.4.4.45 Date.prototype [ @@toPrimitive ] ( hint )
This method is called by ECMAScript language operators to convert a Date to a primitive value. The allowed values for hint are
It performs the following steps when called:
- Let O be the
this value. - If O
is not an Object , throw aTypeError exception. - If hint is either
"string" or"default" , then- Let tryFirst be
string .
- Let tryFirst be
- Else if hint is
"number" , then- Let tryFirst be
number .
- Let tryFirst be
- Else,
- Throw a
TypeError exception.
- Throw a
- Return ?
OrdinaryToPrimitive (O, tryFirst).
This property has the attributes { [[Writable]]:
The value of the
21.4.5 Properties of Date Instances
Date instances are