JavaScript Date Reference Manual
Date object
The Date object is used to handle dates and times.
The Date object is created using new Date().
There are four ways to instantiate a date:
var d = new Date(); var d = new Date(milliseconds); var d = new Date(dateString); var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
For tutorials on dates and times, please read our JavaScript Date Tutorial
Methods and properties of the Date object
Method | Description |
---|---|
new Date() | Return the day of the month (from 1 to 31). |
constructor | Return the function that creates the prototype of the Date object. |
getDate() | Return the day of the month (from 1 to 31). |
getDay() | Return the day of the week (0-6). |
getFullYear() | Return the year. |
getHours() | Return the hour (from 0-23). |
getMilliseconds() | Return the number of milliseconds (0-999). |
getMinutes() | Return the number of minutes (from 0-59). |
getMonth() | Return the month (from 0-11). |
getSeconds() | Return the number of seconds (from 0-59). |
getTime() | Return the number of milliseconds since midnight on January 1, 1970, for the specified date. |
getTimezoneOffset() | Return the time difference between UTC time and local time, in minutes. |
getUTCDate() | Return the day of the month (from 1 to 31) based on UTC. |
getUTCDay() | Return the day of the week (0-6) based on UTC. |
getUTCFullYear() | Return the year based on UTC. |
getUTCHours() | Return the hour (0-23) based on UTC. |
getUTCMilliseconds() | Return the number of milliseconds (0-999) based on UTC. |
getUTCMinutes() | Return the number of minutes (0-59) based on UTC. |
getUTCMonth() | Return the month (0-11) based on UTC. |
getUTCSeconds() | Return the number of seconds (0-59) based on UTC. |
getYear() | Deprecated.Please use The getFullYear() method |
now() | Return the number of milliseconds since midnight on January 1, 1970. |
parse() | Parse a date string and return the number of milliseconds since January 1, 1970. |
prototype | Allows you to add properties and methods to the object. |
setDate() | Set the day of the month in the Date object. |
setFullYear() | Set the year of the date object |
setHours() | Set the hours of the date object. |
setMilliseconds() | Set the milliseconds of the date object. |
setMinutes() | Set the minutes of the date object. |
setMonth() | Set the month of the date object. |
setSeconds() | Set the seconds of the date object. |
setTime() | Set the date to a specified number of milliseconds after/before January 1, 1970. |
setUTCDate() | Set the day of the month in the Date object based on UTC. |
setUTCFullYear() | Set the year of the date object based on UTC. |
setUTCHours() | Set the hours of the date object based on UTC. |
setUTCMilliseconds() | Set the milliseconds of the date object based on UTC. |
setUTCMinutes() | Set the minutes of the date object based on UTC. |
setUTCMonth() | Set the month of the date object based on UTC. |
setUTCSeconds() | Set the seconds of the date object based on UTC. |
setYear() | Deprecated.Please use The setFullYear() method |
toDateString() | Convert the date part of the Date object to a readable string. |
toGMTString() | Deprecated.Please use The toUTCString() method |
toISOString() | Return the date as a string using the ISO standard. |
toJSON() | Return the date in string format, formatted as a JSON date. |
toLocaleDateString() | Return the date part of the Date object as a string using the locale-specific conventions. |
toLocaleTimeString() | Return the time part of the Date object as a string using the locale-specific conventions. |
toLocaleString() | Convert a Date object to a string using the locale-specific conventions. |
toString() | Convert a Date object to a string. |
toTimeString() | Converts the time part of the Date object to a string. |
toUTCString() | Converts the Date object to a string according to world time. |
UTC() | Returns the number of milliseconds since January 1, 1970, at midnight, according to UTC time. |
valueOf() | Return the original value of the Date object. |