W3cubDocs

/JavaScript

Date.prototype

The Date.prototype property represents the prototype for the Date constructor.

Property attributes of Date.prototype
Writable no
Enumerable no
Configurable yes

Description

JavaScript Date instances inherit from Date.prototype. You can modify the constructor's prototype object to affect properties and methods inherited by JavaScript Date instances.

For compatibility with millennium calculations (in other words, to take into account the year 2000), you should always specify the year in full; for example, use 1998, not 98. To assist you in specifying the complete year, JavaScript includes the methods getFullYear(), setFullYear(), getUTCFullYear() and setUTCFullYear().

Starting with ECMAScript 6, the Date.prototype object is itself an ordinary object. It is not a Date instance.

Properties

Date.prototype.constructor
Returns the function that created an instance. This is the Date constructor by default.

Methods

Getter

Date.prototype.getDate()
Returns the day of the month (1-31) for the specified date according to local time.
Date.prototype.getDay()
Returns the day of the week (0-6) for the specified date according to local time.
Date.prototype.getFullYear()
Returns the year (4 digits for 4-digit years) of the specified date according to local time.
Date.prototype.getHours()
Returns the hour (0-23) in the specified date according to local time.
Date.prototype.getMilliseconds()
Returns the milliseconds (0-999) in the specified date according to local time.
Date.prototype.getMinutes()
Returns the minutes (0-59) in the specified date according to local time.
Date.prototype.getMonth()
Returns the month (0-11) in the specified date according to local time.
Date.prototype.getSeconds()
Returns the seconds (0-59) in the specified date according to local time.
Date.prototype.getTime()
Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC (negative for prior times).
Date.prototype.getTimezoneOffset()
Returns the time-zone offset in minutes for the current locale.
Date.prototype.getUTCDate()
Returns the day (date) of the month (1-31) in the specified date according to universal time.
Date.prototype.getUTCDay()
Returns the day of the week (0-6) in the specified date according to universal time.
Date.prototype.getUTCFullYear()
Returns the year (4 digits for 4-digit years) in the specified date according to universal time.
Date.prototype.getUTCHours()
Returns the hours (0-23) in the specified date according to universal time.
Date.prototype.getUTCMilliseconds()
Returns the milliseconds (0-999) in the specified date according to universal time.
Date.prototype.getUTCMinutes()
Returns the minutes (0-59) in the specified date according to universal time.
Date.prototype.getUTCMonth()
Returns the month (0-11) in the specified date according to universal time.
Date.prototype.getUTCSeconds()
Returns the seconds (0-59) in the specified date according to universal time.
Date.prototype.getYear()
Returns the year (usually 2-3 digits) in the specified date according to local time. Use getFullYear() instead.

Setter

Date.prototype.setDate()
Sets the day of the month for a specified date according to local time.
Date.prototype.setFullYear()
Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to local time.
Date.prototype.setHours()
Sets the hours for a specified date according to local time.
Date.prototype.setMilliseconds()
Sets the milliseconds for a specified date according to local time.
Date.prototype.setMinutes()
Sets the minutes for a specified date according to local time.
Date.prototype.setMonth()
Sets the month for a specified date according to local time.
Date.prototype.setSeconds()
Sets the seconds for a specified date according to local time.
Date.prototype.setTime()
Sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC, allowing for negative numbers for times prior.
Date.prototype.setUTCDate()
Sets the day of the month for a specified date according to universal time.
Date.prototype.setUTCFullYear()
Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to universal time.
Date.prototype.setUTCHours()
Sets the hour for a specified date according to universal time.
Date.prototype.setUTCMilliseconds()
Sets the milliseconds for a specified date according to universal time.
Date.prototype.setUTCMinutes()
Sets the minutes for a specified date according to universal time.
Date.prototype.setUTCMonth()
Sets the month for a specified date according to universal time.
Date.prototype.setUTCSeconds()
Sets the seconds for a specified date according to universal time.
Date.prototype.setYear()
Sets the year (usually 2-3 digits) for a specified date according to local time. Use setFullYear() instead.

Conversion getter

Date.prototype.toDateString()
Returns the "date" portion of the Date as a human-readable string.
Date.prototype.toISOString()
Converts a date to a string following the ISO 8601 Extended Format.
Date.prototype.toJSON()
Returns a string representing the Date using toISOString(). Intended for use by JSON.stringify().
Date.prototype.toGMTString()
Returns a string representing the Date based on the GMT (UT) time zone. Use toUTCString() instead.
Date.prototype.toLocaleDateString()
Returns a string with a locality sensitive representation of the date portion of this date based on system settings.
Date.prototype.toLocaleFormat()
Converts a date to a string, using a format string.
Date.prototype.toLocaleString()
Returns a string with a locality sensitive representation of this date. Overrides the Object.prototype.toLocaleString() method.
Date.prototype.toLocaleTimeString()
Returns a string with a locality sensitive representation of the time portion of this date based on system settings.
Date.prototype.toSource()
Returns a string representing the source for an equivalent Date object; you can use this value to create a new object. Overrides the Object.prototype.toSource() method.
Date.prototype.toString()
Returns a string representing the specified Date object. Overrides the Object.prototype.toString() method.
Date.prototype.toTimeString()
Returns the "time" portion of the Date as a human-readable string.
Date.prototype.toUTCString()
Converts a date to a string using the UTC timezone.
Date.prototype.valueOf()
Returns the primitive value of a Date object. Overrides the Object.prototype.valueOf() method.

Specifications

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
The definition of 'Date.prototype' in that specification.
Standard
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Date.prototype' in that specification.
Standard
ECMAScript 2017 Draft (ECMA-262)
The definition of 'Date.prototype' in that specification.
Draft

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Ordinary object ? 41 (41) ? ? ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
Ordinary object ? ? 41.0 (41) ? ? ?

© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype