简体   繁体   中英

How to convert facebook Graph date time into c# DateTime

I have "2010-12-20T11:36:28+0000". How do I parse it into DateTime?

Thanks

DateTime d = DateTime.Parse("2010-12-20T11:36:28+0000");

Works on my machine and parses time zone.

You can use ParseExact or TryParseExact with a Custom Date and Time Format String .

Tested:

var myDate = DateTime.ParseExact("2010-12-20T11:36:28+0000", 
                                 @"yyyy-MM-dd\THH:mm:ssK",
                                 CultureInfo.InvariantCulture);

Having said that, DateTime.Parse works perfectly well.

string date = "2010-12-20T11:36:28+0000";
string start = date.Substring(0, date.IndexOf("T"));
string end = date.Substring(date.IndexOf("T") + 1, date.IndexOf("+") - (date.IndexOf("T") + 1));
DateTime dt = Convert.ToDateTime(start +" "+ end);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM