开发者

c# parse datetime "Fri Jan 14 2011 14:56:36 GMT-0800 (Pacific Standard Time)"

I'm doing

 DateTime dt = DateTime.ParseExact(stringDate, "ddd MMM dd yyyy HH:mm:ss UTCzzzzz zzzz", System.Globalization.CultureInfo.InvariantCulture);

But, that is generating an error (the error was that date was not in the correct format). Do you guys know what the correct syntax is?

The date is:

Fri Jan 14 2011 15:00:39 GMT-0800 (Pacific开发者_如何学编程 Standard Time)


This seems to work if you strip the end of the string.

var stringDate = "Fri Jan 14 2011 15:00:39 GMT-0800";
var dt = DateTime.ParseExact(
        stringDate,
        "ddd MMM dd yyyy HH:mm:ss 'GMT'zzz",
        System.Globalization.CultureInfo.InvariantCulture);


Is Fri Jan 14 2011 15:00:39 GMT-0800 (Pacific Standard Time) what is contained in your time string? If so, your format mask or your input string is incorrect. Please refer to the MSDN library.

This sample is taken from the API documentation

// Parse date and time with custom specifier.
//            Fri Jan 14 2011 15:00:39 GMT-0800
dateString = "Sun 15 Jun 2008 8:30 AM -06:00";
format = "ddd dd MMM yyyy h:mm tt zzz";
try {
   result = DateTime.ParseExact(dateString, format, provider);
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException) {
   Console.WriteLine("{0} is not in the correct format.", dateString);
}

If I had to take a guess, you are not providing the correct time zone format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜