Skip to content Skip to sidebar Skip to footer

Easiest Way To Parse A Javascript Date In C#?

I see that JSON.NET has a DateTime converter: string javascriptJson = JsonConvert.DeserializeObject(entry, new JavaScriptDateTimeConverter()); However I don't have a JSON object,

Solution 1:

The quotes around the date string are required. Also, the returned value is a DateTime, not a string.

DateTime date=
    JsonConvert.DeserializeObject<DateTime>("\"/Date(1276146000000-0500)/\"");

Solution 2:

Does this not work:

DateTimedate= JsonConvert.DeserializeObject<DateTime>(
    "/Date(1276146000000-0500)/", newJavaScriptDateTimeConverter());

Solution 3:

Here is a discussion about this: http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx

Just be sure to read all the comments which contain some good information.

Post a Comment for "Easiest Way To Parse A Javascript Date In C#?"