我试图解析日期戳(我从Twitter获得),但我收到的错误。这里的邮戳:
周五,2010年8月27日22点〇〇分07秒+0000
下面是我的code:
DateTime.ParseExact(MyDateValue,DDD,DD MMM YYYY HH:MM:SS + FFFF,新的CultureInfo(EN-US))
这是我的错误:
System.FormatException是未处理 消息=字符串未被识别为有效的DateTime。
任何人都喜欢走这吗?为了方便我提供了code以下的控制台应用程序表现出了问题。
谢谢 杰米
使用系统;
使用System.Globalization;
类节目
{
静态无效的主要(字串[] args)
{
字符串MyDateValue =星期五,2010年8月27日22点00分○七秒+0000;
VAR DT = DateTime.ParseExact(MyDateValue,DDD,DD MMM YYYY HH:MM:SS + FFFF,新的CultureInfo(EN-US));
}
}
解决方案
这一年符是 YYYY
,不是 YYYY
:
字符串MyDateValue =星期五,2010年8月27日22点○○分07秒+0000;
VAR DT = DateTime.ParseExact(MyDateValue,DDD,DD MMM YYYY HH:MM:SS + FFFF,新的CultureInfo(EN-US));
以上工作正常,只要它不会抛出异常。
我假设 +0000
在字符串的结尾应该是一个时区说明。如果是这样, FFFF
是不正确的,因为它代表了的十万分之三的第二
,而不是时区符,这是 K
。如果它确实应该是时区指示符,那么这将是正确的code:
字符串MyDateValue =星期五,2010年8月27日22点○○分07秒+0000;
VAR DT = DateTime.ParseExact(MyDateValue,DDD,DD MMM YYYY HH:MM:SS K,新的CultureInfo(EN-US));
请参阅 自定义日期和时间格式字符串
。
I'm trying to parse a datestamp (that I got from Twitter) but am receiving errors. here's the datestamp:
Fri, 27 Aug 2010 22:00:07 +0000
Here's my code:
DateTime.ParseExact(MyDateValue, "ddd, dd MMM YYYY HH:mm:ss +ffff", new CultureInfo("en-US"))
and here's my error:
System.FormatException was unhandled Message=String was not recognized as a valid DateTime.
Anyone fancy taking that on? To make it easy I've provided the code below for a console app that exhibits the problem.
Thanks Jamie
using System;
using System.Globalization;
class Program
{
static void Main(string[] args)
{
string MyDateValue = "Fri, 27 Aug 2010 22:00:07 +0000";
var dt = DateTime.ParseExact(MyDateValue, "ddd, dd MMM YYYY HH:mm:ss +ffff", new CultureInfo("en-US"));
}
}
解决方案
The year specifier is yyyy
, not YYYY
:
string MyDateValue = "Fri, 27 Aug 2010 22:00:07 +0000";
var dt = DateTime.ParseExact(MyDateValue, "ddd, dd MMM yyyy HH:mm:ss +ffff", new CultureInfo("en-US"));
The above works fine, as far as that it will not throw an exception.
I am assuming that the +0000
at the end of the string is supposed to be a timezone specifier. If so, the ffff
is incorrect, as it stands for The hundred thousandths of a second
, not the timezone specifier, which is K
. If it is indeed supposed to be the timezone specifier, then this would be the correct code:
string MyDateValue = "Fri, 27 Aug 2010 22:00:07 +0000";
var dt = DateTime.ParseExact(MyDateValue, "ddd, dd MMM yyyy HH:mm:ss K", new CultureInfo("en-US"));
See Custom Date and Time Format Strings
.
上一篇:让付费Android应用免费了一个星期?一个星期、Android
下一篇:抛出:IllegalArgumentException:无效的列抛出、IllegalArgumentException