Defining Dates
The Date object is used to work with dates and times.
We define a Date object with the new keyword. The following code line defines a Date object called myDate:
var myDate=new Date() |
Note: The Date object will automatically hold the current date and time as its initial value!
Manipulate Dates
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 2010):
var myDate=new Date(); |
And in the following example we set a Date object to be 5 days into the future:
var myDate=new Date(); |
Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the Date object itself!
Comparing Dates
The Date object is also used to compare two dates.
The following example compares today's date with the 14th January 2010:
var myDate=new Date(); var today = new Date(); if (myDate>today) Referrence : http://www.w3schools.com/js/js_obj_date.asp |
thanks
what about set the date 5 years in advance?