解析使用PST / CEST / UTC / etc形式的时区的DateTime [英] Parse DateTime with time zone of form PST/CEST/UTC/etc
本文介绍了解析使用PST / CEST / UTC / etc形式的时区的DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解析类似于以下的国际日期时间字符串:
I'm trying to parse an international datetime string similar to:
24-okt-08 21:09:06 CEST
到目前为止,我有一些类似的东西:
So far I've got something like:
CultureInfo culture = CultureInfo.CreateSpecificCulture("nl-BE");
DateTime dt = DateTime.ParseExact("24-okt-08 21:09:06 CEST",
"dd-MMM-yy HH:mm:ss ...", culture);
问题是我应该在格式字符串中使用...查看自定义日期和时间格式字符串 MSDN页面似乎不列出用于解析PST / CEST / GMT / UTC格式的时区的格式字符串。
The problem is what should I use for the '...' in the format string? Looking at the Custom Date and Time Format String MSDN page doesn't seem to list a format string for parsing timezones in PST/CEST/GMT/UTC form.
推荐答案
AFAIK的时区缩写不是认可但是,如果将缩写替换为时区偏移,则可以。例如:
AFAIK the time zone abbreviations are not recognized. However if you replace the abbreviation with the time zone offset, it will be OK. E.g.:
DateTime dt1 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+2"), "dd-MMM-yy HH:mm:ss z", culture);
DateTime dt2 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+02"), "dd-MMM-yy HH:mm:ss zz", culture);
DateTime dt3 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+02:00"), "dd-MMM-yy HH:mm:ss zzz", culture);
这篇关于解析使用PST / CEST / UTC / etc形式的时区的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文