如何在没有时间的情况下将字符串解析为日期时间 [英] How to parse a string to datetime without a time

查看:77
本文介绍了如何在没有时间的情况下将字符串解析为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个带有此值的字符串07/11/2008。如你所见没有时间。


如何将此字符串解析为日期时间变量?我尝试这样做但是我

得到格式不正确的例外。


有什么想法吗?


我尝试了转换...和datetime.par ...


再次感谢!

Hi,

I have a string with this value 07/11/2008. As you see no time included.

How can I parse this string to a datetime variable? I tried to do this but I
get the exception that the format is incorrect.

Any ideas?

I tried both convert... and datetime.par...

Thanks again!

推荐答案

2008年7月3日星期四12:14:52 -0700,Arjen< bo ***** @ hotmail.comwrote:
On Thu, 03 Jul 2008 12:14:52 -0700, Arjen <bo*****@hotmail.comwrote:

I有一个具有此值的字符串07/11/2008。如你所见没有时间。


如何将此字符串解析为日期时间变量?我试图这样做

但是我得到格式不正确的例外。
I have a string with this value 07/11/2008. As you see no time included.

How can I parse this string to a datetime variable? I tried to do this
but I get the exception that the format is incorrect.



您是否尝试过ParseExact()方法?我希望工作正常。

Did you try the ParseExact() method? I would expect that to work fine.




" Peter Duniho" < Np ********* @nnowslpianmk.comschreef in bericht

news:op *************** @ petes-computer.local ...

"Peter Duniho" <Np*********@nnowslpianmk.comschreef in bericht
news:op***************@petes-computer.local...

2008年7月3日星期四12:14:52 -0700,Arjen< bo ***** @ hotmail.comwrote:
On Thu, 03 Jul 2008 12:14:52 -0700, Arjen <bo*****@hotmail.comwrote:

>我有一个字符串,其值为07/11/2008。如您所见,没有时间包括在内。

如何将此字符串解析为日期时间变量?我试图这样做
但我得到格式不正确的例外。
>I have a string with this value 07/11/2008. As you see no time included.

How can I parse this string to a datetime variable? I tried to do this
but I get the exception that the format is incorrect.



您是否尝试过ParseExact()方法?我希望它能正常工作。


Did you try the ParseExact() method? I would expect that to work fine.



我试过这个但是没有用。

DateTime.ParseExact(Request.Form [" date"],@" MM \ / dd \ / YYYY",null);

I tried this but it did not work.
DateTime.ParseExact(Request.Form["date"], @"MM\/dd\/YYYY", null);


Arjen写道:
Arjen wrote:

Peter Duniho < Np ********* @nnowslpianmk.comschreef in bericht

news:op *************** @ petes-computer.local ...
"Peter Duniho" <Np*********@nnowslpianmk.comschreef in bericht
news:op***************@petes-computer.local...

> 2008年7月3日星期四12:14:52 -0700,Arjen< bo ***** @ hotmail.comwrote:
>On Thu, 03 Jul 2008 12:14:52 -0700, Arjen <bo*****@hotmail.comwrote:

>>我有一个字符串,其值为07/11/2008。如您所见,没有时间包括在内。

如何将此字符串解析为日期时间变量?我试着这样做但是我得到了格式不正确的例外情况。
>>I have a string with this value 07/11/2008. As you see no time included.

How can I parse this string to a datetime variable? I tried to do
this but I get the exception that the format is incorrect.


您是否尝试过ParseExact()方法?我希望它能正常工作。


Did you try the ParseExact() method? I would expect that to work fine.



我尝试了这个但它没有用。

DateTime.ParseExact(Request.Form [" date"],@" MM \ / dd \ / YYYY",null);


I tried this but it did not work.
DateTime.ParseExact(Request.Form["date"], @"MM\/dd\/YYYY", null);



尝试使用yyyy代替YYYY。


Arne

Try with yyyy instead of YYYY.

Arne


这篇关于如何在没有时间的情况下将字符串解析为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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