字符串未被识别为有效的日期时间 [英] String was not recognized as a valid date time

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

问题描述

在vb.net中,字符串未被识别为有效的日期时间?

String was not recognized as a valid datetime in vb.net?

推荐答案

可能是因为您正在转换日期它以字符串表示,不在标准日期格式。例如,

It may be because you are converting a date which is represented as a string and is not on the standard date format. Ex,

Dim _dateString As String = "22-2009-11"
Dim _date As DateTime = = DateTime.Parse(_dateString);

抛出异常,因为 _dateString 标准日期格式。您最好的办法是使用 DateTime .ParseExact

throws an exception because _dateString is non-standard date format. The best thing you will do is to use DateTime.ParseExact

Dim _dateString As String = "22-2009-11"
Dim _date As DateTime =  DateTime.ParseExact(_dateString,"dd-yyyy-MM",CultureInfo.InvariantCulture);

这篇关于字符串未被识别为有效的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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