‟Ex igne vita”
The following functions are abstract operations that operate on time values (defined in 15.9.1.1). Note that, in every case, if any argument to one of these functions is NaN, the result will be NaN.
A Date object contains a Number indicating a particular instant in time to within a millisecond. Such a Number is called a time value. A time value may also be NaN, indicating that the Date object does not represent a specific instant of time.
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day. ECMAScript Number values can represent all integers from –9,007,199,254,740,991 to 9,007,199,254,740,991; this range suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.
The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly –100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC. This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC.
The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0.
A given time value t belongs to day number
where the number of milliseconds per day is
msPerDay = 86400000
The remainder is called the time within the day:
TimeWithinDay(t) = t modulo msPerDay
ECMAScript uses an extrapolated Gregorian system to map a day number to a year number and to determine the month and date within that year. In this system, leap years are precisely those which are (divisible by 4) and ((not divisible by 100) or (divisible by 400)). The number of days in year number y is therefore defined by
DaysInYear(y)
= 365 if (y modulo 4) ≠
0
= 366 if (y modulo 4) = 0 and (y modulo 100) ≠
0
= 365 if (y modulo 100) = 0 and (y modulo 400) ≠
0
= 366 if (y modulo 400) = 0
All non-leap years have 365 days with the usual number of days per month and leap years have an extra day in February. The day number of the first day of year y is given by:
DayFromYear(y) = 365 × (y−1970) + floor((y−1969)/4) − floor((y−1901)/100) + floor((y−1601)/400)
The time value of the start of a year is:
TimeFromYear(y) = msPerDay × DayFromYear(y)
A time value determines a year by:
YearFromTime(t) = the largest integer y (closest to positive infinity) such that TimeFromYear(y) ≤ t
The leap-year function is 1 for a time within a leap year and otherwise is zero:
InLeapYear(t) =
0 if DaysInYear(YearFromTime(t)) = 365
= 1 if
DaysInYear(YearFromTime(t)) = 366
Months are identified by an integer in the range 0 to 11, inclusive. The mapping MonthFromTime(t) from a time value t to a month number is defined by:
MonthFromTime(t) =
0 if 0 ≤ DayWithinYear(t)
< 31
= 1 if 31 ≤
DayWithinYear (t) < 59+InLeapYear(t)
=
2 if 59+InLeapYear(t) ≤
DayWithinYear (t) < 90+InLeapYear(t)
=
3 if 90+InLeapYear(t) ≤
DayWithinYear (t) < 120+InLeapYear(t)
=
4 if 120+InLeapYear(t) ≤
DayWithinYear (t) < 151+InLeapYear(t)
=
5 if 151+InLeapYear(t) ≤
DayWithinYear (t) < 181+InLeapYear(t)
=
6 if 181+InLeapYear(t) ≤
DayWithinYear (t) < 212+InLeapYear(t)
=
7 if 212+InLeapYear(t) ≤
DayWithinYear (t) < 243+InLeapYear(t)
=
8 if 243+InLeapYear(t) ≤
DayWithinYear (t) < 273+InLeapYear(t)
=
9 if 273+InLeapYear(t) ≤
DayWithinYear (t) < 304+InLeapYear(t)
=
10 if 304+InLeapYear(t) ≤
DayWithinYear (t) < 334+InLeapYear(t)
=
11 if 334+InLeapYear(t) ≤
DayWithinYear (t) < 365+InLeapYear(t)
where
DayWithinYear(t) = Day(t)−DayFromYear(YearFromTime(t))
A month value of 0 specifies January; 1 specifies February; 2 specifies March; 3 specifies April; 4 specifies May; 5 specifies June; 6 specifies July; 7 specifies August; 8 specifies September; 9 specifies October; 10 specifies November; and 11 specifies December. Note that MonthFromTime(0) = 0, corresponding to Thursday, 01 January, 1970.
A date number is identified by an integer in the range 1 through 31, inclusive. The mapping DateFromTime(t) from a time value t to a month number is defined by:
DateFromTime(t) =
DayWithinYear(t)+1 if MonthFromTime(t)=0
=
DayWithinYear(t)−30 if
MonthFromTime(t)=1
= DayWithinYear(t)−58−InLeapYear(t) if
MonthFromTime(t)=2
= DayWithinYear(t)−89−InLeapYear(t) if
MonthFromTime(t)=3
=
DayWithinYear(t)−119−InLeapYear(t) if
MonthFromTime(t)=4
=
DayWithinYear(t)−150−InLeapYear(t) if
MonthFromTime(t)=5
=
DayWithinYear(t)−180−InLeapYear(t) if
MonthFromTime(t)=6
=
DayWithinYear(t)−211−InLeapYear(t) if
MonthFromTime(t)=7
=
DayWithinYear(t)−242−InLeapYear(t) if
MonthFromTime(t)=8
=
DayWithinYear(t)−272−InLeapYear(t) if
MonthFromTime(t)=9
=
DayWithinYear(t)−303−InLeapYear(t) if
MonthFromTime(t)=10
=
DayWithinYear(t)−333−InLeapYear(t) if
MonthFromTime(t)=11
The weekday for a particular time value t is defined as
WeekDay(t) = (Day(t) + 4) modulo 7
A weekday value of 0 specifies Sunday; 1 specifies Monday; 2 specifies Tuesday; 3 specifies Wednesday; 4 specifies Thursday; 5 specifies Friday; and 6 specifies Saturday. Note that WeekDay(0) = 4, corresponding to Thursday, 01 January, 1970.
An implementation of ECMAScript is expected to determine the local time zone adjustment. The local time zone adjustment is a value LocalTZA measured in milliseconds which when added to UTC represents the local standard time. Daylight saving time is not reflected by LocalTZA. The value LocalTZA does not vary with time but depends only on the geographic location.
An implementation of ECMAScript is expected to determine the daylight saving time algorithm. The algorithm to determine the daylight saving time adjustment DaylightSavingTA(t), measured in milliseconds, must depend only on four things:
(1) the time since the beginning of the year
t – TimeFromYear(YearFromTime(t))
(2) whether t is in a leap year
InLeapYear(t)
(3) the week day of the beginning of the year
WeekDay(TimeFromYear(YearFromTime(t))
and (4) the geographic location.
The implementation of ECMAScript should not try to determine whether the exact time was subject to daylight saving time, but just whether daylight saving time would have been in effect if the current daylight saving time algorithm had been used at the time. This avoids complications such as taking into account the years that the locale observed daylight saving time year round.
If the host environment provides functionality for determining daylight saving time, the implementation of ECMAScript is free to map the year in question to an equivalent year (same leap-year-ness and same starting week day for the year) for which the host environment provides daylight saving time information. The only restriction is that all equivalent years should produce the same result.
Conversion from UTC to local time is defined by
LocalTime(t) = t + LocalTZA + DaylightSavingTA(t)
Conversion from local time to UTC is defined by
UTC(t) = t – LocalTZA – DaylightSavingTA(t – LocalTZA)
Note that UTC(LocalTime(t)) is not necessarily always equal to t.
The following functions are useful in decomposing time values:
HourFromTime(t) = floor(t / msPerHour) modulo HoursPerDay
MinFromTime(t) = floor(t / msPerMinute) modulo MinutesPerHour
SecFromTime(t) = floor(t / msPerSecond) modulo SecondsPerMinute
msFromTime(t) = t modulo msPerSecond
where
HoursPerDay = 24
MinutesPerHour = 60
SecondsPerMinute = 60
msPerSecond = 1000
msPerMinute = 60000 = msPerSecond × SecondsPerMinute
msPerHour = 3600000 = msPerMinute × MinutesPerHour
The operator MakeTime calculates a number of milliseconds from its four arguments, which must be ECMAScript Number values. This operator functions as follows:
If hour is not finite or min is not finite or sec is not finite or ms is not finite, return NaN.
Let h be ToInteger(hour).
Let m be ToInteger(min).
Let s be ToInteger(sec).
Let milli be ToInteger(ms).
Let
t be h *
msPerHour +
m
*
msPerMinute +
s *
msPerSecond +
milli, performing the arithmetic according to IEEE 754 rules
(that is, as if using the ECMAScript operators *
and +
).
Return t.
The operator MakeDay calculates a number of days from its three arguments, which must be ECMAScript Number values. This operator functions as follows:
If year is not finite or month is not finite or date is not finite, return NaN.
Let y be ToInteger(year).
Let m be ToInteger(month).
Let dt be ToInteger(date).
Let ym be y + floor(m /12).
Let mn be m modulo 12.
Find
a value t such that YearFromTime(t) ==
ym and MonthFromTime(t) ==
mn) and DateFromTime(t) ==
1; but if this is not possible (because some argument is out of
range), return NaN.
Return Day(t) + dt − 1.
The operator MakeDate calculates a number of milliseconds from its two arguments, which must be ECMAScript Number values. This operator functions as follows:
If day is not finite or time is not finite, return NaN.
Return day × msPerDay + time.
The operator TimeClip calculates a number of milliseconds from its argument, which must be an ECMAScript Number value. This operator functions as follows:
If time is not finite, return NaN.
If abs(time) > 8.64 x 1015, return NaN.
Return an implementation-dependent choice of either ToInteger(time) or ToInteger(time) + (+0). (Adding a positive zero converts −0 to +0.)
NOTE The point of step 3 is that an implementation is permitted a choice of internal representations of time values, for example as a 64-bit signed integer or as a 64-bit floating-point value. Depending on the implementation, this internal representation may or may not distinguish −0 and +0.
ECMAScript
defines a string interchange format for date-times based upon a
simplification of the ISO 8601 Extended Format. The format is as
follows: YYYY-MM-DDTHH:mm:ss.sss
Z
Where the fields are as follows:
YYYY | is the decimal digits of the year in the Gregorian calendar. |
- | “- ” (hyphen) appears literally twice in the string. |
MM | is the month of the year from 01 (January) to 12 (December). |
DD | is the day of the month from 01 to 31. |
T | “T ” appears literally in the string, to indicate the beginning of the time element. |
HH | is the number of complete hours that have passed since midnight as two decimal digits. |
: | “: ” (colon) appears literally twice in the string. |
mm | is the number of complete minutes since the start of the hour as two decimal digits. |
ss | is the number of complete seconds since the start of the minute as two decimal digits. |
. | “. ” (dot) appears literally in the string. |
sss | is the number of complete milliseconds since the start of the second as three decimal digits. |
Z | is the time zone offset specified as “Z ” (for UTC) or either
“+ ” or “- ” followed by a time expression hh:mm |
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 “T
”
and one of the following time forms with an optional time zone offset
appended:
THH:mm
THH:mm:ss
THH:mm:ss.sss
All
numbers must be base 10.
If the MM
or DD
fields are absent
“01
” is used as the value. If the mm
or
ss
fields are absent “00
” is used as the value
and the value of an absent sss
file is “000
”. The
value of an absent time zone offset is “Z
”.
Illegal values (out-of-bounds as well as syntax errors) in a format string means that the format string is not a valid instance of this format.
NOTE 1 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
NOTE 2 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, ISO 8601 and this format specifies numeric representations of date and time.
ECMAScript requires the ability to specify 6 digit years (extended years); approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC. To represent years before 0 or after 9999, ISO 8601 permits the expansion of the year representation, but only by prior agreement between the sender and the receiver. In the simplified ECMAScript format such an expanded year representation shall have 2 extra year digits and is always prefixed with a + or – sign. The year 0 is considered positive and hence prefixed with a + sign.
When
Date
is called as
a function rather than as a constructor, it returns a String
representing the current time (UTC).
NOTE The
function call Date(
…
)
is not equivalent to the object creation expression new Date(
…
)
with the same arguments.
All
of the arguments are optional; any arguments supplied are accepted
but are completely ignored. A String is created and returned as if
by the expression (new
Date()).toString()
where Date
is the standard built-in constructor with that name and toString
is the standard built-in method Date.prototype.toString
.
When
Date
is called as
part of a new
expression, it is a constructor: it initialises the newly created
object.
When Date is called with two to seven arguments, it computes the date from year, month, and (optionally) date, hours, minutes, seconds and ms.
The
[[Prototype]] internal property of the newly constructed object is
set to the original Date prototype object, the one that is the
initial value of Date.prototype
(15.9.4.1).
The
[[Class]] internal property of the newly constructed object is set
to "Date"
.
The [[Extensible]] internal property of the newly constructed object is set to true.
The [[PrimitiveValue]] internal property of the newly constructed object is set as follows:
Let y be ToNumber(year).
Let m be ToNumber(month).
If date is supplied then let dt be ToNumber(date); else let dt be 1.
If hours is supplied then let h be ToNumber(hours); else let h be 0.
If minutes is supplied then let min be ToNumber(minutes); else let min be 0.
If seconds is supplied then let s be ToNumber(seconds); else let s be 0.
If ms is supplied then let milli be ToNumber(ms); else let milli be 0.
If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, then let yr be 1900+ToInteger(y); otherwise, let yr be y.
Let finalDate be MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)).
Set the [[PrimitiveValue]] internal property of the newly constructed object to TimeClip(UTC(finalDate)).
The
[[Prototype]] internal property of the newly constructed object is
set to the original Date prototype object, the one that is the
initial value of Date.prototype
(15.9.4.1).
The
[[Class]] internal property of the newly constructed object is set
to "Date"
.
The [[Extensible]] internal property of the newly constructed object is set to true.
The [[PrimitiveValue]] internal property of the newly constructed object is set as follows:
Let v be ToPrimitive(value).
If Type(v) is String, then
Parse
v as a date, in exactly the same manner as for the parse
method (15.9.4.2); let V be the time value for this date.
Else, let V be ToNumber(v).
Set the [[PrimitiveValue]] internal property of the newly constructed object to TimeClip(V) and return.
The
[[Prototype]] internal property of the newly constructed object is
set to the original Date prototype object, the one that is the
initial value of Date.prototype
(15.9.4.1).
The
[[Class]] internal property of the newly constructed object is set
to "Date"
.
The [[Extensible]] internal property of the newly constructed object is set to true.
The [[PrimitiveValue]] internal property of the newly constructed object is set to the time value (UTC) identifying the current time.
The value of the [[Prototype]] internal property of the Date constructor is the Function prototype object (15.3.4).
Besides
the internal properties and the length
property (whose value is 7
),
the Date constructor has the following properties:
The
initial value of Date.prototype
is the built-in Date prototype object (15.9.5).
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
The
parse
function
applies the ToString operator to its argument and interprets the
resulting String as a date and time; it returns a Number, the UTC
time value corresponding to the date and time. The String may be
interpreted as a local time, a UTC time, or a time in some other
time zone, depending on the contents of the String. The function
first attempts to parse the format of the String according to the
rules called out in Date Time String Format (15.9.1.15). If the
String does not conform to that format the function may fall back to
any implementation-specific heuristics or implementation-specific
date formats. Unrecognizable Strings or dates containing illegal
element values in the format String shall cause Date.parse
to return NaN.
If x is any Date object 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 Date.parse
is implementation-dependent when given any String value that does
not conform to the Date Time String Format (15.9.1.15) and that
could not be produced in that implementation by the toString
or toUTCString
method.
When
the UTC
function
is called with fewer than two arguments, the behaviour is
implementation-dependent. When the UTC
function is called with two to seven arguments, it computes the date
from year, month
and (optionally) date,
hours, minutes,
seconds and ms.
The following steps are taken:
Let y be ToNumber(year).
Let m be ToNumber(month).
If date is supplied then let dt be ToNumber(date); else let dt be 1.
If hours is supplied then let h be ToNumber(hours); else let h be 0.
If minutes is supplied then let min be ToNumber(minutes); else let min be 0.
If seconds is supplied then let s be ToNumber(seconds); else let s be 0.
If ms is supplied then let milli be ToNumber(ms); else let milli be 0.
If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, then let yr be 1900+ToInteger(y); otherwise, let yr be y.
Return TimeClip(MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli))).
The
length
property of
the UTC
function
is 7.
NOTE The
UTC
function differs from
the Date
constructor in
two ways: it returns a time value as a Number, rather than creating
a Date object, and it interprets the arguments in UTC rather than as
local time.
The
now
function
return a Number value that is the time value designating the UTC
date and time of the occurrence of the call to now
.
The
Date prototype object is itself a Date object (its [[Class]] is
"Date"
)
whose [[PrimitiveValue]] is NaN.
The value of the [[Prototype]] internal property of the Date prototype object is the standard built-in Object prototype object (15.2.4).
In
following descriptions of functions that are properties of the Date
prototype object, the phrase “this Date object” refers to the
object that is the this value for the invocation of the
function. Unless explicitly noted otherwise, none of these functions
are generic; a TypeError exception is thrown if the this
value is not an object for which the value of the [[Class]] internal
property is "Date"
.
Also, the phrase “this time value” refers to the Number value
for the time represented by this Date object, that is, the value of
the [[PrimitiveValue]] internal property of this Date object.
The
initial value of Date.prototype.constructor
is the built-in Date
constructor.
This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form.
NOTE For
any Date value d
whose milliseconds amount is zero, the result of
Date.parse(
d
.toString())
is equal to d
.valueOf()
.
See 15.9.4.2.
This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the “date” portion of the Date in the current time zone in a convenient, human-readable form.
This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the “time” portion of the Date in the current time zone in a convenient, human-readable form.
This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions of the host environment’s current locale.
NOTE The first parameter to this function is likely to be used in a future version of this standard; it is recommended that implementations do not use this parameter position for anything else.
This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the “date” portion of the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions of the host environment’s current locale.
NOTE The first parameter to this function is likely to be used in a future version of this standard; it is recommended that implementations do not use this parameter position for anything else.
This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the “time” portion of the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions of the host environment’s current locale.
NOTE The first parameter to this function is likely to be used in a future version of this standard; it is recommended that implementations do not use this parameter position for anything else.
The
valueOf
function
returns a Number, which is this time value.
Return this time value.
Let t be this time value.
If t is NaN, return NaN.
Return YearFromTime(LocalTime(t)).
Let t be this time value.
If t is NaN, return NaN.
Return YearFromTime(t).
Let t be this time value.
If t is NaN, return NaN.
Return MonthFromTime(LocalTime(t)).
Let t be this time value.
If t is NaN, return NaN.
Return MonthFromTime(t).
Let t be this time value.
If t is NaN, return NaN.
Return DateFromTime(LocalTime(t)).
Let t be this time value.
If t is NaN, return NaN.
Return DateFromTime(t).
Let t be this time value.
If t is NaN, return NaN.
Let t be this time value.
If t is NaN, return NaN.
Return WeekDay(t).
Let t be this time value.
If t is NaN, return NaN.
Return HourFromTime(LocalTime(t)).
Let t be this time value.
If t is NaN, return NaN.
Return HourFromTime(t).
Let t be this time value.
If t is NaN, return NaN.
Return MinFromTime(LocalTime(t)).
Let t be this time value.
If t is NaN, return NaN.
Return MinFromTime(t).
Let t be this time value.
If t is NaN, return NaN.
Return SecFromTime(LocalTime(t)).
Let t be this time value.
If t is NaN, return NaN.
Return SecFromTime(t).
Let t be this time value.
If t is NaN, return NaN.
Return msFromTime(LocalTime(t)).
Let t be this time value.
If t is NaN, return NaN.
Return msFromTime(t).
Returns the difference between local time and UTC time in minutes.
Let t be this time value.
If t is NaN, return NaN.
Return (t − LocalTime(t)) / msPerMinute.
Set the [[PrimitiveValue]] internal property of this Date object to v.
Return v.
Let t be the result of LocalTime(this time value).
Let time be MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ToNumber(ms)).
Set the [[PrimitiveValue]] internal property of this Date object to u.
Return u.
Let t be this time value.
Let time be MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ToNumber(ms)).
Set the [[PrimitiveValue]] internal property of this Date object to v.
Return v.
If ms
is not specified, this behaves as if ms
were specified with the value getMilliseconds()
.
Let t be the result of LocalTime(this time value).
Let s be ToNumber(sec).
If ms is not specified, then let milli be msFromTime(t); otherwise, let milli be ToNumber(ms).
Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli)).
Set the [[PrimitiveValue]] internal property of this Date object to u.
Return u.
The
length
property of
the setSeconds
method is 2.
If ms
is not specified, this behaves as if ms
were specified with the value getUTCMilliseconds()
.
Let t be this time value.
Let s be ToNumber(sec).
If ms is not specified, then let milli be msFromTime(t); otherwise, let milli be ToNumber(ms).
Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli)).
Let v be TimeClip(date).
Set the [[PrimitiveValue]] internal property of this Date object to v.
Return v.
The
length
property of
the setUTCSeconds
method is 2.
If
sec is not
specified, this behaves as if sec
were specified with the value getSeconds()
.
If ms
is not specified, this behaves as if ms
were specified with the value getMilliseconds()
.
Let t be the result of LocalTime(this time value).
Let m be ToNumber(min).
If sec is not specified, then let s be SecFromTime(t); otherwise, let s be ToNumber(sec).
If ms is not specified, then let milli be msFromTime(t); otherwise, let milli be ToNumber(ms).
Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)).
Set the [[PrimitiveValue]] internal property of this Date object to u.
Return u.
The
length
property of
the setMinutes
method is 3.
If
sec is not
specified, this behaves as if sec
were specified with the value getUTCSeconds()
.
If ms
is not specified, this function behaves as if ms
were specified with the value return by getUTCMilliseconds()
.
Let t be this time value.
Let m be ToNumber(min).
If sec is not specified, then let s be SecFromTime(t); otherwise, let s be ToNumber(sec).
If ms is not specified, then let milli be msFromTime(t); otherwise, let milli be ToNumber(ms).
Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)).
Let v be TimeClip(date).
Set the [[PrimitiveValue]] internal property of this Date object to v.
Return v.
The
length
property of
the setUTCMinutes
method is 3.
If
min is not
specified, this behaves as if min
were specified with the value getMinutes()
.
If
sec is not
specified, this behaves as if sec
were specified with the value getSeconds()
.
If ms
is not specified, this behaves as if ms
were specified with the value getMilliseconds()
.
Let t be the result of LocalTime(this time value).
Let h be ToNumber(hour).
If min is not specified, then let m be MinFromTime(t); otherwise, let m be ToNumber(min).
If If sec is not specified, then let s be SecFromTime(t); otherwise, let s be ToNumber(sec).
If ms is not specified, then let milli be msFromTime(t); otherwise, let milli be ToNumber(ms).
Set the [[PrimitiveValue]] internal property of this Date object to u.
Return u.
The
length
property of
the setHours
method is 4.
If
min is not
specified, this behaves as if min
were specified with the value getUTCMinutes()
.
If
sec is not
specified, this behaves as if sec
were specified with the value getUTCSeconds()
.
If ms
is not specified, this behaves as if ms
were specified with the value getUTCMilliseconds()
.
Let t be this time value.
Let h be ToNumber(hour).
If min is not specified, then let m be MinFromTime(t); otherwise, let m be ToNumber(min).
If sec is not specified, then let s be SecFromTime(t); otherwise, let s be ToNumber(sec).
If ms is not specified, then let milli be msFromTime(t); otherwise, let milli be ToNumber(ms).
Let v be TimeClip(newDate).
Set the [[PrimitiveValue]] internal property of this Date object to v.
Return v.
The
length
property of
the setUTCHours
method is 4.
Let t be the result of LocalTime(this time value).
Let dt be ToNumber(date).
Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), TimeWithinDay(t)).
Set the [[PrimitiveValue]] internal property of this Date object to u.
Return u.
Let t be this time value.
Let dt be ToNumber(date).
Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), TimeWithinDay(t)).
Let v be TimeClip(newDate).
Set the [[PrimitiveValue]] internal property of this Date object to v.
Return v.
If
date is not
specified, this behaves as if date
were specified with the value getDate()
.
Let t be the result of LocalTime(this time value).
Let m be ToNumber(month).
If date is not specified, then let dt be DateFromTime(t); otherwise, let dt be ToNumber(date).
Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t)).
Set the [[PrimitiveValue]] internal property of this Date object to u.
Return u.
The
length
property of
the setMonth
method is 2.
If
date is not
specified, this behaves as if date
were specified with the value getUTCDate()
.
Let t be this time value.
Let m be ToNumber(month).
If date is not specified, then let dt be DateFromTime(t); otherwise, let dt be ToNumber(date).
Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t)).
Let v be TimeClip(newDate).
Set the [[PrimitiveValue]] internal property of this Date object to v.
Return v.
The
length
property of
the setUTCMonth
method is 2.
If
month is not
specified, this behaves as if month
were specified with the value getMonth()
.
If
date is not
specified, this behaves as if date
were specified with the value getDate()
.
Let t be the result of LocalTime(this time value); but if this time value is NaN, let t be +0.
Let y be ToNumber(year).
If month is not specified, then let m be MonthFromTime(t); otherwise, let m be ToNumber(month).
If date is not specified, then let dt be DateFromTime(t); otherwise, let dt be ToNumber(date).
Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)).
Set the [[PrimitiveValue]] internal property of this Date object to u.
Return u.
The
length
property of
the setFullYear
method is 3.
If
month is not
specified, this behaves as if month
were specified with the value getUTCMonth()
.
If
date is not
specified, this behaves as if date
were specified with the value getUTCDate()
.
Let t be this time value; but if this time value is NaN, let t be +0.
Let y be ToNumber(year).
If month is not specified, then let m be MonthFromTime(t); otherwise, let m be ToNumber(month).
If date is not specified, then 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 the [[PrimitiveValue]] internal property of this Date object to v.
Return v.
The
length
property of
the setUTCFullYear
method is 3.
This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in a convenient, human-readable form in UTC.
NOTE The
intent is to produce a String representation of a date that is more
readable than the format specified in 15.9.1.15. It is not essential
that the chosen format be unambiguous or easily machine parsable. If
an implementation does not have a preferred human-readable format it
is recommended to use the format defined in 15.9.1.15 but with a
space rather than a “T
”
used to separate the date and time elements.
This function returns a String value represent the instance in time represented by this Date object. The format of the String is the Date Time string format defined in 15.9.1.15. All fields are present in the String. The time zone is always UTC, denoted by the suffix Z. If the time value of this object is not a finite Number a RangeError exception is thrown.
This
function provides a String representation of a Date object for use
by JSON.stringify
(15.12.3).
When
the toJSON
method
is called with argument key,
the following steps are taken:
Let O be the result of calling ToObject, giving it the this value as its argument.
Let tv be ToPrimitive(O, hint Number).
If tv is a Number and is not finite, return null.
Let
toISO be the result of calling the [[Get]] internal method
of O with argument "toISOString
".
If IsCallable(toISO) is false, throw a TypeError exception.
Return the result of calling the [[Call]] internal method of toISO with O as the this value and an empty argument list.
NOTE 1 The argument is ignored.
NOTE 2 The toJSON
function is intentionally generic; it does not require that its this
value be a Date object. Therefore, it can be transferred to other
kinds of objects for use as a method. However, it does require that
any such object have a toISOString
method. An object is free to use the argument key
to filter its stringification.
Date
instances inherit properties from the Date prototype object and
their [[Class]] internal property value is "Date"
.
Date instances also have a [[PrimitiveValue]] internal property.
The [[PrimitiveValue]] internal property is time value represented by this Date object.