The Date object is used to work with dates and times.
For a complete reference of all the properties and methods that can be used with the Date object, go to our complete Date object reference.
The reference contains a brief description and examples of use for each property and method
Date objects are created with the Date() constructor.
There are four ways of instantiating a date:
Most parameters above are optional. Not specifying, causes 0 to be passed in.
Once a Date object is created, a number of methods allow you to operate on it. Most methods allow you to get and set the year, month, day, hour, minute, second, and milliseconds of the object, using either local time or UTC (universal, or GMT) time.
All dates are calculated in milliseconds from 01 January, 1970 00:00:00 Universal Time (UTC) with a day containing 86,400,000 milliseconds.
Some examples of instantiating a date:
We can easily manipulate the date by using the methods available for the Date object.
In the example below we set a Date object to a specific date (14th January 2015):
And in the following example we set a Date object to be 5 days into the future:
Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the Date object itself
The Date object is also used to compare two dates.
The Below example compares today's date with the 14th January 2015:
Your Query was successfully sent!