【问题标题】:How to calculate daylight savings switchover dates for EU?如何计算欧盟的夏令时转换日期?
【发布时间】:2022-12-11 05:52:53
【问题描述】:

给定一个 UTC 时间戳,我想确定当时 DST 在欧盟是否处于活动状态。

【问题讨论】:

    标签: c dst


    【解决方案1】:

    从 3 月的最后一个星期日 (02:00 CET) 到 10 月的最后一个星期日 (03:00 CEST) 实行夏令时。 (https://en.wikipedia.org/wiki/Summer_time_in_Europe)。要测试,比较例如与https://www.timeanddate.com/time/change/germany?year=2022

    #include <stdio.h>
    #include <stdlib.h>
    
    //included for reference only
    int wd(int y, int m, int d)
    {
        return (d += m<3?y--:y-2, 23*m/9 + d+4 + y/4 - y/100 + y/400) % 7;
        //https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Keith
    }
    
    #define GregorianAdpotion 1752
    int main(int argc, char *argv[])
    {
        int y = argc > 1 ? atoi(argv[1]) : 2022;
        if (y <= GregorianAdpotion)
            return 1;
        //https://rosettacode.org/wiki/Find_the_last_Sunday_of_each_month#FreeBASIC
        int x = 33+y + y/4 - y/100 + y/400; //common part of Keith for Mar and Oct
        int last_Sun_March = 31 - x % 7;
        int last_Sun_Oct = 31 - (4 + x) % 7;
        printf("DST from %d-03-%d 02:00 CET ", y, last_Sun_March);
        printf("to %d-10-%d 03:00 CEST
    ", y, last_Sun_Oct);
        return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-09
      • 2011-08-01
      • 2013-12-09
      • 1970-01-01
      • 2017-08-28
      • 2015-12-17
      • 2018-03-03
      • 2014-05-19
      相关资源
      最近更新 更多