我有一个字符串Value = "12/11/2013"
并尝试解析这个使用C#,数据分析错误与DateTime.ParseExact
DateTime.ParseExact(Value, "dd/MM/yyyy", null);
但有一个例外FormatException
,不能为什么已了解。
我有一个字符串Value = "12/11/2013"
并尝试解析这个使用C#,数据分析错误与DateTime.ParseExact
DateTime.ParseExact(Value, "dd/MM/yyyy", null);
但有一个例外FormatException
,不能为什么已了解。
变化:
DateTime.ParseExact(Value, "dd/MM/yyyy", null);
要:
DateTime.ParseExact(Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
你应该注意,通过'null'将采取当前的文化 – 2013-04-04 10:21:40
这对我来说可能...可能是一些winphone的副作用 – 2013-04-04 10:40:22
从您的个人资料看来,你是be-By
culture下,这就是为什么你所得到的例外。以下代码将产生相同的异常。
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("be-BY");
string Value = "12/11/2013";
DateTime dt = DateTime.ParseExact(Value, "dd/MM/yyyy", null);
要comeover异常使用CultureInfo.InvariantCulture
,如:
DateTime dt = DateTime.ParseExact(Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
你可以试试这个:
DateTime.ParseExact(Value, "dd'/'MM'/'yyyy", null);
尝试'DateTime.ParseExact(价值, “DD/MM/YYYY” 的CultureInfo .InvariantCulture);' – Habib 2013-04-04 10:20:44
适合我。我没有收到任何错误。线程运行的文化是什么? – Oded 2013-04-04 10:21:47
没有错误发生..其工作对我来说很好... – Pandian 2013-04-04 10:24:49