Javascript Date() constructor doesn’t work

It is the definition of the Date object to use values 0-11 for the month field.

I believe that the constructor using a String is system-dependent (not to mention locale/timezone dependent) so you are probably better off using the constructor where you specify year/month/day as seperate parameters.

BTW, in Firefox,

new Date("04/02/2008");

works fine for me – it will interpret slashes, but not hyphens. I think this proves my point that using a String to construct a Date object is problemsome. Use explicit values for month/day/year instead:

new Date(2008, 3, 2);

Leave a Comment