开发者

C# Convert yyyymmdd to datetime

I'm trying to convert开发者_如何学Python the UTC Time on Server that located overseas to local time e.g. Australia. Could anyone please help me to achieve this

Thanks.


DateTime.ParseExact(s, "yyyyMMdd").ToLocalTime()

The MM needs to be capital, because mm means minutes, not months.


Use DateTime.Parse().

If the input string does not have the timezone offset included (for example, 03/01/2009 05:42:00 -5:00, Sat, 01 Nov 2008 19:35:00 GMT or 2008-11-01T19:35:00.0000000-07:00), then ensure that the DateTme.Kind is "Utc", then call DateTime.ToLocal() to convert it to the local time zone.


Would you not be better using

DateTime.TryParse(String DateString, out DateTime result)

Then should anything be wrong you won't get the exception thrown - you can check the values instead (or use a IF)!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜