Init javascript Date object
I would like to retrieve a Javascript object Date for new year. I want to user new Date(); o开发者_如何学编程bject and init it to the 2009-01-01 (it's for a countdown).
Thanks
The month part of the construct is an enum, so it's always themonthyouwant -1. And are you sure you want to count down to 2009? oh well...
var newYears = new Date(2009, 0, 1);
From http://www.w3schools.com/js/js_obj_date.asp, you can init your js date object with
var date= new Date(year, month, day, hours, minutes, seconds, milliseconds);
You may also use date.setFullYear(year,month,day) method if your date object has been created before. Please note that month is between 0 and 11 just like what David Hedlund said.
use...
dateVariable.setTime(Date.parse('1/1/2009 12:00 AM'));
精彩评论