错误的无效日期时间字符串 [英] Error invalid datetime string

查看:85
本文介绍了错误的无效日期时间字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我获得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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆