Date instance that represents a single moment in time in a platform-independent format.
Date objects contain a
Number that represents milliseconds since 1 January 1970 UTC.
new Date() new Date(value) new Date(dateString) new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]])
备注： The only correct way to instantiate a new
Date object is by using the
new operator. If you simply call the
Date object directly, such as
now = Date(), the returned value is a string rather than a
There are four basic forms for the
No parametersWhen no parameters are provided, the newly-created
Dateobject represents the current date and time as of the time of instantiation.
Time value or timestamp number
An integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC (the ECMAScript epoch, equivalent to the UNIX epoch), with leap seconds ignored. Keep in mind that most UNIX Timestamp functions are only accurate to the nearest second.
A string value representing a date, specified in a format recognized by the
Date.parse()method. (These formats are IETF-compliant RFC 2822 timestamps, and also strings in a version of ISO8601.)
备注： Parsing of date strings with the
Date.parse(), which works the same way) is strongly discouraged due to browser differences and inconsistencies.
- Support for RFC 2822 format strings is by convention only.
- Support for ISO 8601 formats differs in that date-only strings (e.g.
"1970-01-01") are treated as UTC, not local.
Individual date and time component valuesGiven at least a year and month, this form of
Dateobject whose component values (year, month, day, hour, minute, second, and millisecond) all come from the following parameters. Any missing fields are given the lowest possible value (
0for every other component).
Integer value representing the year.
99map to the years
1999. All other values are the actual year. See the example below.
Integer value representing the month, beginning with
0for January to
Integer value representing the day of the month. The default is
Integer value representing the hour of the day. The default is
Integer value representing the minute segment of a time. The default is
0minutes past the hour.
Integer value representing the second segment of a time. The default is
0seconds past the minute.
Integer value representing the millisecond segment of a time. The default is
0milliseconds past the second.
|ECMAScript Language Specification |
BCD tables only load in the browser