无法将字符串转换为dateTime [英] Cannot convert a string to the dateTime

查看:93
本文介绍了无法将字符串转换为dateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好, 

Hi all , 

执行以下代码 

On executing the below code 

  DateTime昨天= Convert.ToDateTime(" 02-MAR-18 10:44:44 AM");

    var dateTime = DateTime.ParseExact(yesterday.ToString()," dd-MMM-yy hh:mm:ss tt",CultureInfo.InvariantCulture);

  DateTime yesterday = Convert.ToDateTime("02-MAR-18 10:44:44 AM");
   var dateTime = DateTime.ParseExact(yesterday.ToString(),"dd-MMM-yy hh:mm:ss tt",CultureInfo.InvariantCulture);

我得到的错误就像字符串不是有效的格式转换为DateTime。 

I get the error like the string is not in the valid format to convert to DateTime . 

如果有人可以向我推荐一些想法,那将会非常有用通过这个。 

Would be really helpful if anyone could suggest me some ideas to get through this . 

提前致谢 

Thanks in advance 

sauthee

推荐答案

您好,

尝试

DateTime.Parse()

DateTime.Parse()

DateTime.ParseExact()

DateTime.ParseExact()


这篇关于无法将字符串转换为dateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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