当解析奇怪的错误字符串到日期? [英] Strange error when parsing string to date?
本文介绍了当解析奇怪的错误字符串到日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我试图解析日期是这样的:
日期时间T1 = DateTime.ParseExact(2013年8月11日,下午十一时00分00秒,MMMM DD,YYYY,HH:MM:SS TT,System.Globalization .CultureInfo.InvariantCulture);
它工作正常,但是当我做的事情是这样的:
字符串s =2013年8月11号,下午十一时00分00秒;
日期时间T = DateTime.ParseExact(S,MMMM DD,YYYY,HH:MM:SS TT,System.Globalization.CultureInfo.InvariantCulture);
我得到这个错误:
键入System.FormatException的异常mscorlib.ni.dll发生,但在用户code没有处理
解决方案
由于您的字符串
字符串s =2013年8月11号,下午十一时00分00秒;
含 0x200e(8206)字符的开始和结束的对月
。您可以通过
VAR字符= s.ToCharArray();
似乎是一个复制粘贴+问题
您可以删除这些字符:的
VAR中newstr =新的字符串(s.Where(C => C< 128).ToArray())
When I try to parse date like this:
DateTime t1 = DateTime.ParseExact("August 11, 2013, 11:00:00 PM", "MMMM dd, yyyy, hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture);
It works correctly but when I do thing like this :
string s ="August 11, 2013, 11:00:00 PM";
DateTime t = DateTime.ParseExact(s, "MMMM dd, yyyy, hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture);
I get this error :
An exception of type 'System.FormatException' occurred in mscorlib.ni.dll but was not handled in user code
解决方案
Because your string
string s = "August 11, 2013, 11:00:00 PM";
Includes 0x200e(8206) character at the beginning and end of August
. You can see it easily by
var chars = s.ToCharArray();
Seems to be a copy+paste problem
You can remove those chars by:
var newstr = new string(s.Where(c => c <128).ToArray())
这篇关于当解析奇怪的错误字符串到日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文