Date methods let you get and set date values (years, months, days, minutes, seconds, milliseconds)
Get methods are used for getting a part of a date. Here are the most common (alphabetically):
Method | Description |
---|---|
getDate() | Get the day as a number (1-31) |
getDay() | Get the weekday as a number (0-6) |
getFullYear() | Get the four digit year (yyyy) |
getHours() | Get the hour (0-23) |
getMilliseconds() | Get the milliseconds (0-999) |
getMinutes() | Get the minutes (0-59) |
getMonth() | Get the month (0-11) |
getSeconds() | Get the seconds (0-59) |
getTime() | Get the time (milliseconds since January 1, 1970) |
getTime() returns the the number of milliseconds since 01.01.1970:
getFullYear() returns the year of a date as a four digit number:
getDay() returns the weekday as a number (0-6):
You can use an array of names, and getDay() to return the weekday as a name:
Set methods are used for setting a part of a date. Here are the most common (alphabitically):
Method | Description |
---|---|
setDate() | Set the day as a number (1-31) |
setFullYear() | Set the year (optionally month and day yyyy.mm.dd) |
setHours() | Set the hour (0-23) |
setMilliseconds() | Set the milliseconds (0-999) |
setMinutes() | Set the minutes (0-59) |
setMonth() | Set the month (0-11) |
setSeconds() | Set the seconds (0-59) |
setTime() | Set the time (milliseconds since January 1, 1970) |
setFullYear() sets a date object to a specific date. In this example, to January 14, 2020:
setDate() sets the day of the month (1-31):
The setDate() method can also be used to add days to a date:
![]() |
If adding days, shifts the month or year, the changes are handled automatically by the Date object. |
---|
If you have an input value (or any string), you can use the Date.parse() method to convert it to milliseconds.
Date.parse() returns the number of milliseconds between the date and January 1, 1970:
You can then use the number of milliseconds to convert it to a date object:
Dates can easily be compared.
The following example compares today's date with January 14, 2100:
![]() |
JavaScript counts months from 0 to 11. January is 0. December is 11. |
---|
For a complete reference, go to our Complete JavaScript Date Reference.
The reference contains descriptions and examples of all Date properties and methods.