0

I am instantiating a Javascript Date object in my script using the setFullYear, setMonth,....methods in the Date object. But the resulting Date object shows the year and month as 1+. For example if I set the year to 2012 and month to 12. The Date object would show up as 2013, January....

How can I avoid this?

Thanks.

1 Answer 1

3

Month is zero-based. You should set 11 for December.

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/setMonth

Sign up to request clarification or add additional context in comments.

4 Comments

I'll +1 this if you remove the link to w3schools and replace with developer.mozilla.org/en-US/docs/JavaScript/Reference/… w3schools is renowned for misinformation/errors
and there's your +1. Seriously, have a look at the last link I posted.
@LeeTaylor, thanks for the link. I am not aware of that previously. w3schools always come up top in Google's search result page. So I thought the information in their site is reliable.
No worries. The worrying this is that many people probably believe they're reliable too. Also, Mozilla's documentation is well regarded.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.