Javascript date to C# via Ajax
You can use DateTime.ParseExact which allows you to specify a format string to be used for parsing:
DateTime dt = DateTime.ParseExact("Wed Dec 16 00:00:00 UTC-0400 2009",
"ddd MMM d HH:mm:ss UTCzzzzz yyyy",
CultureInfo.InvariantCulture);
The most reliable way would be to use milliseconds since the epoch. You can easily get this in JavaScript by calling Date.getTime()
. Then, in C# you can convert it to a DateTime like this:
long msSinceEpoch = 1260402952906; // Value from Date.getTime() in JavaScript
return new DateTime(1970, 1, 1).AddTicks(msSinceEpoch * 10000);
You have to multiply by 10,000 to convert from milliseconds to "ticks", which are 100 nanoseconds.