views:

46

answers:

3

Hi,

I would like to retrieve a Javascript object Date for new year. I want to user new Date(); object and init it to the 2009-01-01 (it's for a countdown).

Thanks

+3  A: 

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);
David Hedlund
A: 

use...

dateVariable.setTime(Date.parse('1/1/2009 12:00 AM'));

George
+1  A: 

From http://www.w3schools.com/js/js%5Fobj%5Fdate.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.

Anton Setiawan