c#解析日期时间“2011年1月14日星期五14:56:36 GMT-0800(太平洋标准时间)”

我正在做

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

但是,这会产生错误(错误是日期格式不正确)。 你们知道正确的语法是什么吗?

日期是:

2011年1月14日星期五15:00:39 GMT-0800(太平洋标准时间)

如果你去掉字符串的末尾,这似乎有效。

 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); 

Fri Jan 14 2011 15:00:39 GMT-0800 (Pacific Standard Time)你的时间字符串中包含什么? 如果是这样,您的格式掩码或输入字符串不正确。 请参阅MSDN库。

此示例取自API文档

 // 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); } 

如果我不得不猜测,你没有提供正确的时区格式。