1

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

1

3 Answers 3

3

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);
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

0

use...

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.