new Date returns incorrect value

new Date(2012, 12, 31) returns Thu Jan 31 00:00:00 MUT 2013

No, this is actually a correct date.
Months in new Date() are zero-based. So december is actually 11.
Using 12 would push the whole date to the next year.

Understandable but not intuitive. To be consistent, the first date of the month should be 0…

ylockson:
Understandable but not intuitive. To be consistent, the first date of the month should be 0…

and what about the year
let’s start at 1 B.C… :mrgreen:

ylockson:
Understandable but not intuitive. To be consistent, the first date of the month should be 0…

True, but that’s the way the ECMAScript spec (ECMAScript Language Specification - ECMA-262 Edition 5.1) is written.

If you want to use 1 based months you can always do

new Date('2013/01/20');
new Date('01/20/2013');

Each of those will return Jan 20, 2013

jgarfield,

Thanks for your input.

I am new to Servoy & Javascript and came to realize that Servoy’s methods needed to mimick Javascript’s exactly identically. I also realized that often times, it is better to google ‘how to … in javascript’ than to search Servoy’s wikis.

Regards.

ylockson:
I am new to Servoy & Javascript and came to realize that Servoy’s methods needed to mimick Javascript’s exactly identically. I also realized that often times, it is better to google ‘how to … in javascript’ than to search Servoy’s wikis.

Actually Servoy’s methods are not mimicking JavaScript. It is JavaScript. It’s just that you are coding against the Servoy Object Model (SOM) instead of the Document Object Model in a web-browser (DOM). So the objects are different, the language is the same.
And true, I believe Servoy’s wiki assumes some level of JavaScript knowledge. But as you said there are plenty of sources on the web that have very good JavaScript primers.