Asp>净日期时间转换 [英] Asp>net datetime conversion
问题描述
HI,
我们需要将字符串值(2016/02/22)转换为DATETIME OR DATE,其中包含8个字符表示该值应为(yyyyMMdd) )with Date varable。
Date值的格式应为8个字符。当我们尝试将字符串转换为Date
字符串未被识别 一个有效的DateTime
,发生错误。
我尝试过:
我们需要将一个字符串值(2016/02/22)转换为DATETIME OR DATE,其中包含8个字符,表示该值应为(yyyyMMdd),并且日期可变。
日期值的格式应为8个字符。当我们尝试将字符串转换为日期
字符串未被识别 一个有效的DateTime
,发生错误。
尝试使用以下代码ParseExact
:
string timeStr = 2016/02/22;
DateTime dtObject = DateTime.ParseExact(timeStr, yyyy / MM / dd,CultureInfo .InvariantCulture);
按照以下链接对您有所帮助:
在C#中将字符串解析为DateTime对象的不同方法 [ ^ ]
HI,
We need to convert a string value(2016/02/22) to DATETIME OR DATE with 8 characters means the value should be in (yyyyMMdd) with Date varable.
The Format of the Date value should be 8 characters.When we tried to convert the string to Date "
String was not recognized as a valid DateTime
",error occuring.
What I have tried:
We need to convert a string value(2016/02/22) to DATETIME OR DATE with 8 characters means the value should be in (yyyyMMdd) with Date varable.
The Format of the Date value should be 8 characters.When we tried to convert the string to Date "
String was not recognized as a valid DateTime
",error occuring.
Try with below code withParseExact
:
string timeStr = "2016/02/22"; DateTime dtObject = DateTime.ParseExact(timeStr, "yyyy/MM/dd", CultureInfo.InvariantCulture);
Follow below link that may help you:
Different Ways to Parse string to DateTime Object in C#[^]
这篇关于Asp>净日期时间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!