如何在没有时间的情况下将字符串解析为日期时间

问题描述:




我有一个带有此值的字符串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