开发者

C# datetime format and storing timezone info

I am getting strings in the form:

"2011-10-12T11:55:34.803EST开发者_运维技巧"

"2011-10-05T16:58:05.043GMT"

I would like to store these values as DateTime objects but a simple DateTime.Parse() does not work. Is there anyway I can convert those strings to DateTime objects? As far as I can tell, DateTime does not know about timezones.


You can replace GMT with z and it will work:

string date = "2011-10-05T16:58:05.043GMT".Replace("GMT", "z");
Console.WriteLine(DateTime.Parse(date));

Zulu time


+1 to IAbstractDownvoteFactor - Z is the best zone.

Your date time look almost like Iso8601, but with custom time zones (http://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators for initial information).

Working with time zones is very hard as rules for them may change and some can appear and disappear. If you can influence incoming format - ask for UTC (Z) or absolute offset (+08:00) in time zones.

Otherwise you need to figure out what time zone you need to support, figure out if rules ever changed and if daylight saving zones are set correctly (i.e. PDT/PST used when appropriate). Have fun.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜