scriptsharp
scriptsharp copied to clipboard
new DateTime, one month difference in C# and javascript
In C# I write DateTime date = new DateTime(2011, 1, 1); Help says: month: The month (1 through 12).
This line is converted in Javascript as follows: var date = new Date(2011, 1, 1);
But javascript counts months from 0 to 11. The result is one month difference in javascript and C# code.
Maybe I have to setup locale correctly or something like that?
The doc-comments (and hence intellisense) for DateTime ctor in the script# mscorlib indicate the correct range. This isn't a locale issue... these are the semantics of Date object in script.
The compiler cannot auto-subtract... as it is ambiguous whether to do or not. It would also have to auto add on retrieval.