2

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?

asked Jul 22, 2010 at 15:23

3 Answers 3

2

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)/\"");
answered Jul 22, 2010 at 16:47

1 Comment

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!
0

Does this not work:

DateTime date = JsonConvert.DeserializeObject<DateTime>(
 "/Date(1276146000000-0500)/", new JavaScriptDateTimeConverter());
answered Jul 22, 2010 at 15:31

Comments

0

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.

answered Jul 22, 2010 at 15:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.