解析字符串到日期时出现奇怪的错误? [英] Strange error when parsing string to date?
本文介绍了解析字符串到日期时出现奇怪的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试解析这样的日期时:
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);
我收到此错误:
An exception of type 'System.FormatException' occurred in mscorlib.ni.dll but was not handled in user code
推荐答案
因为你的字符串
string s = "August 11, 2013, 11:00:00 PM";
包含 0x200e(8206)字符。你可以通过
var chars = s.ToCharArray();
似乎是一个复制+粘贴问题
Seems to be a copy+paste problem
可以通过以下方式删除这些字符:
var newstr = new string(s.Where(c => c <128).ToArray())
这篇关于解析字符串到日期时出现奇怪的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文