这是一个用于说明问题的小代码示例:
enter code here
var offset1 = DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Moscow")
.GetUtcOffset(Instant.FromDateTimeUtc(DateTime.UtcNow));
var offset2 = DateTimeZoneProviders.Tzdb.GetZoneOrNull("Etc/GMT+3")
.GetUtcOffset(Instant.FromDateTimeUtc(DateTime.UtcNow));
Console.WriteLine(offset1 + " vs " + offset2);
结果" {+ 03} vs {-03}"
答案 0 :(得分:1)
是的,这是对的。那是因为" Etc / GMT + X"区域ID令人困惑。它们与POSIX TZ字符串匹配,这些字符串由于某种原因表示UTC与本地时间的偏移"而不是当地时间与UTC"的正常偏差。请参阅维基百科list of tz database time zone以确认。
来自etcetra
文件:
# Be consistent with POSIX TZ settings in the Zone names,
# even though this is the opposite of what many people expect.
# POSIX has positive signs west of Greenwich, but many people expect
# positive signs east of Greenwich. For example, TZ='Etc/GMT+4' uses
# the abbreviation "-04" and corresponds to 4 hours behind UT
# (i.e. west of Greenwich) even though many people would expect it to
# mean 4 hours ahead of UT (i.e. east of Greenwich).
如果要创建表示固定偏移量的时区,可以使用" UTC + X"的标识符。或使用DateTimeZone.ForOffset
。