Вопрос

I got format exception when trying to parse this

// input string "Wed Mar 12 2014 17:50:15 GMT+0000 (UTC)"
DateTime.Parse(response.LastActivityDate); 

A first chance exception of type System.FormatException

How can I parse it this input string ? What culture is this ?

thank you in advance!

Это было полезно?

Решение

Here, have some fish:

string value = "Wed Mar 12 2014 17:50:15 GMT+0000 (UTC)";
value = value.Replace("GMT","").Replace("(UTC)","").Trim();
value = value.Insert(value.Length - 2, ":");
DateTime parsed = DateTime.ParseExact(value, "ddd MMM dd yyyy HH:mm:ss zzz", 
                                      CultureInfo.InvariantCulture);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top