该字符串未被识别为有效的日期时间 [英] The string was not recognized as a valid datetime

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

问题描述

objfile.dateFileDate = convert.ToDatetime(Format(txtdate.text,"MM/dd/yyyy hh:mm"))

objfile.dateFileDate=convert.ToDatetime(Format(txtdate.text,"MM/dd/yyyy hh:mm"))

以下错误即将到来

该字符串未被识别为有效的日期时间.未知从0开始的单词.

The string was not recognized as a valid datetime .There is an unknown word starting at 0.

我该怎么做才能保存此日期时间,请帮助

What should i do to save this datetime, please help

推荐答案

您不能使用日期时间格式设置普通文本的格式.

You can't format normal text using datetime formats.

尝试

C#

objfile.dateFileDate=DateTime.ParseExact(txtdate.text, "MM/dd/yyyy hh:mm", null);

VB.NET

objfile.dateFileDate=DateTime.ParseExact(txtdate.text, "MM/dd/yyyy hh:mm", Nothing)

这是假设dateFileDate是DateTime类型,并且txtdate.text是上面的格式.

This is assuming dateFileDate is a DateTime type and that the txtdate.text is in the above format.

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

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