Peter
Peter

Reputation: 38555

c# Parse json Date?

I get a json date from a webservice that i need to parse manualy and the date looks like this: "Fri, 06 Nov 2009 00:00:00 -0800"

How would i parse this into a datetime object?

I guess i should use DateTime.ParseExact but what do i feed into it.

Upvotes: 3

Views: 4609

Answers (5)

Ravi Ram
Ravi Ram

Reputation: 24488

// parse JSON formatted date to javascript date object

var date = new Date(parseInt(jsonDate.substr(6)));

// format display date (e.g. 04/10/2012)

THEN

var displayDate = $.datepicker.formatDate("mm/dd/yy", date);

from http://blog.degree.no/bloggere/

Upvotes: 0

Pete OHanlon
Pete OHanlon

Reputation: 9146

I ran this code and it worked fine:

string date = "Fri, 06 Nov 2009 00:00:00 -0800";
DateTime dt = DateTime.Parse(date);

Upvotes: 1

Rubens Farias
Rubens Farias

Reputation: 57996

Check it out: Converting String to DateTime C#.net

Upvotes: 0

alexn
alexn

Reputation: 59002

var date = DateTime.Parse("Fri, 06 Nov 2009 00:00:00 -0800"); works fine.

Upvotes: 2

JaredPar
JaredPar

Reputation: 755457

Just use DateTime.Parse. I verified it works for this string.

Upvotes: 9

Related Questions