views:

69

answers:

3

I see that JSON.NET has a DateTime converter:

string javascriptJson = JsonConvert.DeserializeObject(entry, new JavaScriptDateTimeConverter());

However I don't have a JSON object, I simply have a string:

/Date(1276146000000-0500)/

I could create an object, add the date, then parse it, but this seems common enough that there should be a way to do this in a single line. Is there anything out there?

A: 

Does this not work:

DateTime date = JsonConvert.DeserializeObject<DateTime>(
    "/Date(1276146000000-0500)/", new JavaScriptDateTimeConverter());
Matthew Abbott
It doesn't work for me.
Greg
A: 

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.

Mark Schultheiss
+2  A: 

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)/\"");
Greg
Perfect! I had a really ugly Regex taking out the numbers, adjusting for local time and then doing adding the number to the epoch time!
chum of chance