Asp>净日期时间转换 [英] Asp>net datetime conversion

查看:59
本文介绍了Asp>净日期时间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 with ParseExact:

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屋!

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