错误的无效日期时间字符串 [英] Error invalid datetime string
问题描述
我获得Excel值2,例如"30/5/2017"
然后搜索堆栈溢出,使用3种方法仍然得到错误的无效日期时间字符串
DateTime d1 = DateTime.ParseExact((String)DateRng.Value2,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture);
DateTime d1 = DateTime.ParseExact((String)DateRng.Value2,"dd/MM/yyyy",null);
DateTime d1 = DateTime.Parse((String)DateRng.Value2);
MEALY
是的,尽管如此,MSDN上的示例也总是很难理解.
它应该解析为dateTime,而不像许多示例显示为字符串一样.
DateTime d1 = DateTime.ParseExact("30/5/2017","dd/M/yyyy",null);
i get Excel value2 such as "30/5/2017"
then search stackoverflow, using 3 methods still got error invalid datetime string
DateTime d1 = DateTime.ParseExact((String)DateRng.Value2, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
DateTime d1 = DateTime.ParseExact((String)DateRng.Value2, "dd/MM/yyyy", null);
DateTime d1 = DateTime.Parse((String)DateRng.Value2);
MEALY
Yea the sample on MSDN has also always been difficult to understand while it is so easy.
It should parse to a dateTime and not like many samples show to a string.
DateTime d1 = DateTime.ParseExact("30/5/2017", "dd/M/yyyy", null);
这篇关于错误的无效日期时间字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!