NodaTime ZonedDateTime不考虑时钟向前
本文关键字:时钟 不考虑 ZonedDateTime NodaTime | 更新日期: 2023-09-27 18:15:59
来自Jon Skeet的NodaTime文档:
然而,当我尝试这段代码时,有效地从NodaCode文档中复制并粘贴大部分代码到应用程序中,我们添加的时间是有效的"经验"时间-就好像我们只是等了二十分钟。然而,在那天凌晨1点,时钟欧洲/伦敦时区的时间提前了一个小时,所以我们结束了当地时间是凌晨2点05分,而不是你可能预期的凌晨1点05分
after
变量具有01:05:00,而不是02:05:00。为什么它没有考虑到时区?DateTimeZone london = DateTimeZoneProviders.Tzdb["Europe/London"];
LocalDateTime local = new LocalDateTime(2012, 3, 27, 0, 45, 00);
ZonedDateTime before = london.AtStrictly(local);
ZonedDateTime after = before + Duration.FromMinutes(20);
Debug.WriteLine("local = {0}",local);
Debug.WriteLine("before adding 20 minutes = {0}", before);
Debug.WriteLine("after adding 20 minutes= {0}", after);
输出:local = 03/27/2012 00:45:00
before adding 20 minutes = 2012-03-27T00:45:00 Europe/London (+01)
after adding 20 minutes= 2012-03-27T01:05:00 Europe/London (+01)
更新:
根据下面Dean Ward的回答,我尝试了26号,仍然没有实现夏令时的改变。(
DateTimeZone london = DateTimeZoneProviders.Tzdb["Europe/London"];
LocalDateTime local = new LocalDateTime(2012, 3, 26, 0, 45, 00);
ZonedDateTime before = london.AtStrictly(local);
ZonedDateTime after = before + Duration.FromMinutes(20);
输出:local = 03/26/2012 00:45:00
before adding 20 minutes = 2012-03-26T00:45:00 Europe/London (+01)
after adding 20 minutes= 2012-03-26T01:05:00 Europe/London (+01)
2012年欧洲/伦敦夏令时于2012-03-25更改。尝试将初始值更改为该日期…