Date in ECMAScript 262
Date/time value.
Inherits from:
Self Methods
| name | returns | description |
|---|---|---|
| parse(dateString) | Number | Attempt to parse the supplied string as a date, and return the number of milliseconds it represents. |
| UTC(year,month,[day],…) | Number | Return the number of milliseconds corresponding to the supplied arguments. |
Instance Properties
| name | type | description |
|---|---|---|
| constructor | Object | A reference to the constructor class for the current object instance. [from Object] |
| prototype | Object | The prototype for a class. [from Object] |
Instance Methods
| name | returns | description |
|---|---|---|
| getDate() | Number | Return the day number in the local timezone. |
| getDay() | Number | Return the zero-based weekday number in the local timezone. |
| getFullYear() | Number | Return the four-digit year in the local timezone. |
| getHours() | Number | Return the hour number in the local timezone. |
| getMilliseconds() | Number | Return the millisecond number in the local timezone. |
| getMinutes() | Number | Return the minute number in the local timezone. |
| getMonth() | Number | Return the zero-based month number in the local timezone. |
| getSeconds() | Number | Return the second number in the local timezone. |
| getTime() | Number | Return the number of milliseconds since Midnight, Jan 1, 1970 UTC. |
| getTimezoneOffset() | Number | Returns the difference between the local time and UTC time in minutes. |
| getUTCDate() | Number | Return the day number in UTC. |
| getUTCDay() | Number | Return the zero-based weekday number in UTC. |
| getUTCFullYear() | Number | Return the four-digit year in UTC. |
| getUTCHours() | Number | Return the hour number in UTC. |
| getUTCMilliseconds() | Number | Return the millisecond number in UTC. |
| getUTCMinutes() | Number | Return the minute number in UTC. |
| getUTCMonth() | Number | Return the zero-based month number in UTC. |
| getUTCSeconds() | Number | Return the second number in UTC. |
| hasOwnProperty(propertyOrMethodName) | Boolean | Determines if the object/instance itself has the named property or method. [from Object] |
| isPrototypeOf(instanceToTest) | Boolean | Determines if the calling object prototype is in the inheritance chain for the supplied argument. [from Object] |
| propertyIsEnumerable(propertyOrMethodName) | Boolean |
Determines if the object/instance itself has a property or method of the supplied name which will appear in a for (prop in obj) enumeration.
[from Object]
|
| setDate(day) | Number | Set the day number in the local timezone. |
| setFullYear(year,[month],[day]) | Number | Set the year, expressed in the local timezone. |
| setHours(hours,[mins],[secs],…) | Number | Set the hour number in the local timezone. |
| setMilliseconds(ms) | Number | Set the millisecond number in the local timezone. |
| setMinutes(mins,[secs],[ms]) | Number | Set the minute number in the local timezone. |
| setMonth(month,[day]) | Number | Set the zero-based month, expressed in the local timezone. |
| setSeconds(second,[ms]) | Number | Set the second number in the local timezone. |
| setTime(time) | Number | Set the date object to a new time. |
| setUTCDate(day) | Number | Set the UTC day number. |
| setUTCFullYear(year,[month],[day]) | Number | Set the UTC year number. |
| setUTCHours(hours,[mins],[secs],…) | Number | Set the UTC hours. |
| setUTCMilliseconds([ms]) | Number | Set the UTC milliseconds. |
| setUTCMinutes(mins,[secs],[ms]) | Number | Set the UTC minutes. |
| setUTCMonth(month,[day]) | Number | Set the UTC month. |
| setUTCSeconds(secs,[ms]) | Number | Set the UTC seconds. |
| toDateString() | String | Return a string version of the date-only portion of the object. |
| toLocaleString() | String |
For most objects, the same as toString() unless explicitly overridden.
[from Object]
|
| toString() | String | Returns a string representation of the object. [from Object] |
| toTimeString() | String | Return a string version of the time-only portion of the object. |
| toUTCString() | String | Returns a string form of the Date in a convenient, human-readable form in UTC. |
| valueOf() | String |
Returns the internal this value of the object.
[from Object]
|
Description
The ECMAScript date object stores time/date information with 1 millisecond precision, as a Number measured from Midnight, January 1st, 1970 UTC.
As a signed 64-bit integer, the internal Number storing the date can theoretically cover a range of 285,616 years before or after Jan-1-1970; however, the specifications state that the actual range is exactly 100,000,000 days forwards or backwards. (Roughly 273,972 years.)
Creating a date using the new Date() constructor without any argument sets the time to the current time. Alternatively, the constructor may be passed a string which it will attempt to parse as a date/time, a single number representing the number of milliseconds since Midnight January 1st, 1970 UTC, or two or more numbers for various parts of the date:
var now = new Date();
var dateFromMS = new Date(1071764127813);
var someDate = new Date('11/18/2003'); //Date.parse() used internally
var dateAndTime = new Date('11/18/2003 4:15:27 pm'); //Date.parse() used internally
var exactDate = new Date(2003,11,18,16,15,27,813); //Date.UTC() used internallyInternally, when a single string is passed, Date.parse() is called and the return value used to create the date. When two or more numbers are passed, Date.UTC() is called and its result used.