Date function in JavaScript
Posted by David on March 19th, 2007 filed in JavaScriptReturn today’s date and time
How to use the Date() method to get today’s date.
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!
In the example below we set a Date object to a specific date (14th January 2010):
var myDate=new Date()
myDate.setFullYear(2010,0,14)
myDate.setFullYear(2010,0,14)
And in the following example we set a Date object to be 5 days into the future:
var myDate=new Date()
myDate.setDate(myDate.getDate()+5)
myDate.setDate(myDate.getDate()+5)