scriptsharp icon indicating copy to clipboard operation
scriptsharp copied to clipboard

new DateTime, one month difference in C# and javascript

Open utkez opened this issue 15 years ago • 1 comments

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?

utkez avatar Aug 31 '11 13:08 utkez

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.

nikhilk avatar Aug 31 '11 14:08 nikhilk