开发者

Parse a full datetime string to DateTime type

I need to Parse this string "Wed Jun 01 2011 00:00:00 GMT+0300 (GTB Daylight Time)" into a DateTime! can this be done in开发者_开发百科 .NET Framework?

[EDIT]

I think the problem is how to express this (GTB Daylight Time)...

Thank you.


Sure. Use DateTime.ParseExact or DateTime.TryParseExact.


Assuming you have valid reasons why you're extracting the date on the client via GetValue() before passing it to the server (instead of accessing the server-side dateEdit.Date property)....:

GetValue() (or GetDate() for that matter) return a JavaScript date object. You can format it using JavaScript's built-in getXXX() methods specified here. before passing it to a server, such as:

dt.GetValue().getMonth() + '/' + dt.GetValue().getDate() + '/' + dt.GetValue().getFullYear()

=> returns '5/8/2011', which you can parse using .NET's DateTime.Parse/ParseExact methods.

But really, you should double-check whether extracting the date on the client (instead of using the server-side properties) is the best way to go.


This looks like:

"ddd MMM dd yyyy HH:mm:ss zzz"


It looks like you have more information in the string than DateTime can handle. Have you considered using DateTimeOffset.Parse. Once you have parsed the DateTimeOffset, refer to this article to convert it to DateTime (if you need to) http://msdn.microsoft.com/en-us/library/bb546101.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜