【问题标题】:NodaTime ZonedDateTime not considering clocks going forwardNodaTime ZonedDateTime 不考虑未来的时钟
【发布时间】:2014-08-01 08:07:31
【问题描述】:

来自 Jon Skeet 的 NodaTime documentation

我们添加的时间实际上是“经验”时间 - 好像我们会 只是等了二十分钟。然而,当天凌晨 1 点,时钟 在欧洲/伦敦时区前进一个小时 - 所以我们结束了 当地时间是凌晨 2:05,而不是您预期的凌晨 1:05

但是,当我尝试此代码时,有效地将大部分代码从 NodaCode 文档复制并粘贴到应用程序中,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 的回答,我尝试使用 26th 代替,但它仍然没有实现夏令时更改。 :(

        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)

【问题讨论】:

    标签: c# nodatime


    【解决方案1】:

    2012 年欧洲/伦敦的 DST 更改为 2012-03-25。尝试将您的初始值更改为该日期...

    【讨论】:

    • 恐怕它还是一样的,试着用那个日期。我会在一分钟内发布上面的更新代码
    • 改为尝试 25 日。请注意,您的初始日期输出为 +01,因此它认为它已经在 DST 中。
    • 啊..没错...现在它显示 2:05 ...谢谢...文档在链接中说 27,猜测需要修复。 :)
    • @user113981:谢谢 - 现在会解决这个问题。
    • 这让乔恩印象深刻。 1 小时错误周转。愿所有软件出品一样好。你可以大企业 25% 的维护,但情况更糟;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多