.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

Javascript: Setting the Month on a Date Object

While working with dates in Javascript I came across some weirdness that was messing with my date parsing. Apparently in Javascript, years and days are 1-based, but months are 0-based. To set the correct date:

var someDate = new Date(yourYear, yourMonth - 1, yourDay);

Crazy, I know, but hopefully this helps someone out.

July 28, 2009 Posted by | Javascript, Tips & Tricks | | Leave a comment