C# 日期时间格式和存储时区信息
我得到的字符串格式为:
"2011-10-12T11:55:34.803EST"
"2011-10-05T16:58:05.043GMT"
我想将这些值存储为 DateTime 对象,但使用简单的 DateTime.Parse()不起作用。无论如何,我可以将这些字符串转换为 DateTime 对象吗?据我所知, DateTime 不知道时区。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 GMT 替换为 z,它将起作用:
祖鲁时间
You can replace GMT with z and it will work:
Zulu time
IAbstractDownvoteFactor +1 - Z 是最佳区域。
您的日期时间看起来几乎像 Iso8601,但具有自定义时区(http://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators 了解初始信息)。
使用时区非常困难,因为它们的规则可能会发生变化,并且有些规则可能会出现和消失。如果您可以影响传入格式 - 请求 UTC (Z) 或时区的绝对偏移量 (+08:00)。
否则,您需要弄清楚需要支持哪个时区,弄清楚规则是否曾经更改以及夏令时区是否设置正确(即在适当时使用 PDT/PST)。玩得开心。
+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.