[英]String Date to DateTime Format
I have a string with a value of 13/12/17,09:37:20+32 I cant convert it in datetime format. 我有一个值为13/12 / 17,09:37:20 + 32的字符串,我无法将其转换为日期时间格式。 Error always occur saying that the "String was not recognized as a valid DateTime".
总是发生错误,指出“字符串未被识别为有效的DateTime”。 This is my code:
这是我的代码:
DateTime crtdDate = DateTime.ParseExact(l.CreateDate, "yy/MM/dd,hh:mm:ss tt", CultureInfo.InvariantCulture);
Please someone help me.Thanks! 请有人帮我。谢谢!
tt
represents either am
or pm
tt
代表am
或pm
+32 won't be parsed by tt. tt不会解析+32。 If you are trying to parse hundreths of a second, try
ff
. 如果要解析一秒的百分之一,请尝试
ff
。
var crtdDate = DateTime.ParseExact(l.CreateDate, "yy/MM/dd,hh:mm:ss+ff", CultureInfo.InvariantCulture);
Your string must match the format exactly: 您的字符串必须与格式完全匹配:
l.CreateDate = "06/15/2008";
[http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx][1]
"d" -> 6/15/2009 1:45:30 PM -> 6/15/2009 (en-US)
6/15/2009 1:45:30 PM -> 15/06/2009 (fr-FR)
6/15/2009 1:45:30 PM -> 2009/06/15 (ja-JP)
DateTime.ParseExact(l.CreateDate, "d", CultureInfo.InvariantCulture);
Without the +32, this will parse: 没有+32,这将解析:
DateTime.ParseExact("13/12/17,09:37:20", "yy/MM/dd,hh:mm:ss", CultureInfo.InvariantCulture);
Use a valid timezone specifier, the following will work: 使用有效的时区说明符,以下内容将起作用:
DateTime crtdDate = DateTime.ParseExact("13/12/17,09:37:20+00:00", "yy/MM/dd,hh:mm:ssK",
CultureInfo.InvariantCulture);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.