【问题标题】:Timezone database file format question时区数据库文件格式问题
【发布时间】:2011-06-11 17:19:53
【问题描述】:

我正在读取从Olson 数据库生成的时区文件,以查找时区何时更改以及它们更改为什么。 tzfile.h 中描述了时区文件的格式。

对于我的问题,我将使用我获得的欧洲/罗马数据。

我可能让它正常工作,因为我的输出正确匹配 timeanddate.com 所说的内容。例如,我的程序正确地说:

1982 年 3 月 28 日 02:00:00 时区更改为 GMT +2.000000。

1982 年 9 月 26 日 03:00:00 时区更改为 GMT +1.000000。

这在此处得到确认: http://www.timeanddate.com/worldclock/clockchange.html?n=215&year=1982

但是,我不确定是否需要使用 tzh_ttisstdcnt 和 tzh_ttisgmtcnt。

来自 tzfile.h:

然后有 tzh_ttisstdcnt 标准/墙壁指示器,每个存储 作为一个字节的值;他们告诉是否 相关的过渡时间 指定了本地时间类型 作为标准时间或挂钟时间, 并且在时区文件为 用于处理 POSIX 风格的时区 环境变量。

最后还有 tzh_ttisgmtcnt UTC/本地指标,每个都存储为 一字节值;他们告诉是否 相关的过渡时间 与本地时间类型是 指定为 UTC 或本地时间,以及 使用时区文件时使用 在处理 POSIX 风格的时区 环境变量。

我发现每个“时间类型”(ttinfo 结构)都有一个 isstd 和 isgmt 字节。 以下是欧洲/罗马的 6 种“时间类型”:

 Type 0, CEST, DST? = 1, GMT+2, isstd? = 1, isgmt? = 0
 Type 1, CET,  DST? = 0, GMT+1, isstd? = 1, isgmt? = 0
 Type 2, CEST, DST? = 1, GMT+2, isstd? = 0, isgmt? = 0
 Type 3, CET,  DST? = 0, GMT+1, isstd? = 0, isgmt? = 0
 Type 4, CEST, DST? = 1, GMT+2, isstd? = 1, isgmt? = 1
 Type 5, CET,  DST? = 0, GMT+1, isstd? = 1, isgmt? = 1

tzfile.h 听起来像是 isstd 和 isgmt 告诉您转换时间是如何存储的(gmt vs localtime)。但是,我的代码当前假定所有转换时间都存储为 GMT。对于所有 6 种转换类型,我的程序的输出都与 timeanddate.com 匹配。

另外,我不明白类型 0 和 1 如何可以是 std 而不是 gmt。我以为 GMT 是标准时间。

任何解释都会很棒。

编辑:

当我忽略 isstd 和 isgmt 选项时,我的输出似乎与 timeanddate.com 上的数据几乎匹配。我目前将所有转换时间解释为 GMT:

罗马的过渡类型:

新类型 0: isdst = 1 偏移量 = 7200 缩写 = 0 isstd = 1 isgmt = 0

新类型 1: isdst = 0 偏移量 = 3600 缩写 = 5 isstd = 1 isgmt = 0

新类型 2: isdst = 1 偏移量 = 7200 缩写 = 0 isstd = 0 isgmt = 0

新类型 3: isdst = 0 偏移量 = 3600 缩写 = 5 isstd = 0 isgmt = 0

新类型 4: isdst = 1 偏移量 = 7200 缩写 = 0 isstd = 1 isgmt = 1

罗马的数据(假设所有过渡时间均以 GMT 时间给出):

The starting timezone is GMT+1
type: 0, transition time in file:-1690851600
Add previous offset to get transition as (localtime): June 03, 1916 00:00:00 GMT+2

**type: 1, transition time in file:-1680483600
Add previous offset to get transition as (localtime): October 01, 1916 01:00:00 GMT+1**

type: 0, transition time in file:-1664758800
Add previous offset to get transition as (localtime): April 01, 1917 00:00:00 GMT+2

type: 1, transition time in file:-1649034000
Add previous offset to get transition as (localtime): September 30, 1917 01:00:00 GMT+1

type: 0, transition time in file:-1635123600
Add previous offset to get transition as (localtime): March 10, 1918 00:00:00 GMT+2

type: 1, transition time in file:-1616979600
Add previous offset to get transition as (localtime): October 06, 1918 01:00:00 GMT+1

type: 0, transition time in file:-1604278800
Add previous offset to get transition as (localtime): March 02, 1919 00:00:00 GMT+2

type: 1, transition time in file:-1585530000
Add previous offset to get transition as (localtime): October 05, 1919 01:00:00 GMT+1

type: 0, transition time in file:-1571014800
Add previous offset to get transition as (localtime): March 21, 1920 00:00:00 GMT+2

type: 1, transition time in file:-1555290000
Add previous offset to get transition as (localtime): September 19, 1920 01:00:00 GMT+1

type: 0, transition time in file:-932432400
Add previous offset to get transition as (localtime): June 15, 1940 00:00:00 GMT+2

type: 1, transition time in file:-857257200
Add previous offset to get transition as (localtime): November 02, 1942 03:00:00 GMT+1

type: 0, transition time in file:-844556400
Add previous offset to get transition as (localtime): March 29, 1943 02:00:00 GMT+2

type: 1, transition time in file:-828226800
Add previous offset to get transition as (localtime): October 04, 1943 03:00:00 GMT+1

type: 0, transition time in file:-812502000
Add previous offset to get transition as (localtime): April 03, 1944 02:00:00 GMT+2

type: 1, transition time in file:-798080400
Add previous offset to get transition as (localtime): September 17, 1944 01:00:00 GMT+1

type: 2, transition time in file:-781052400
Add previous offset to get transition as (localtime): April 02, 1945 02:00:00 GMT+2

type: 1, transition time in file:-766717200
Add previous offset to get transition as (localtime): September 15, 1945 01:00:00 GMT+1

type: 0, transition time in file:-750898800
Add previous offset to get transition as (localtime): March 17, 1946 02:00:00 GMT+2

type: 1, transition time in file:-733359600
Add previous offset to get transition as (localtime): October 06, 1946 03:00:00 GMT+1

type: 0, transition time in file:-719456400
Add previous offset to get transition as (localtime): March 16, 1947 00:00:00 GMT+2

type: 1, transition time in file:-701917200
Add previous offset to get transition as (localtime): October 05, 1947 01:00:00 GMT+1

type: 0, transition time in file:-689209200
Add previous offset to get transition as (localtime): February 29, 1948 02:00:00 GMT+2

type: 1, transition time in file:-670460400
Add previous offset to get transition as (localtime): October 03, 1948 03:00:00 GMT+1

type: 2, transition time in file:-114051600
Add previous offset to get transition as (localtime): May 22, 1966 00:00:00 GMT+2

type: 3, transition time in file:-103168800
Add previous offset to get transition as (localtime): September 25, 1966 00:00:00 GMT+1

type: 2, transition time in file:-81997200
Add previous offset to get transition as (localtime): May 28, 1967 00:00:00 GMT+2

type: 3, transition time in file:-71719200
Add previous offset to get transition as (localtime): September 24, 1967 00:00:00 GMT+1

type: 2, transition time in file:-50547600
Add previous offset to get transition as (localtime): May 26, 1968 00:00:00 GMT+2

type: 3, transition time in file:-40269600
Add previous offset to get transition as (localtime): September 22, 1968 00:00:00 GMT+1

type: 2, transition time in file:-18493200
Add previous offset to get transition as (localtime): June 01, 1969 00:00:00 GMT+2

type: 3, transition time in file:-8215200
Add previous offset to get transition as (localtime): September 28, 1969 00:00:00 GMT+1

type: 2, transition time in file:12956400
Add previous offset to get transition as (localtime): May 31, 1970 00:00:00 GMT+2

type: 3, transition time in file:23234400
Add previous offset to get transition as (localtime): September 27, 1970 00:00:00 GMT+1

type: 2, transition time in file:43801200
Add previous offset to get transition as (localtime): May 23, 1971 00:00:00 GMT+2

type: 3, transition time in file:54687600
Add previous offset to get transition as (localtime): September 26, 1971 01:00:00 GMT+1

type: 2, transition time in file:75855600
Add previous offset to get transition as (localtime): May 28, 1972 00:00:00 GMT+2

type: 3, transition time in file:86738400
Add previous offset to get transition as (localtime): October 01, 1972 00:00:00 GMT+1

type: 2, transition time in file:107910000
Add previous offset to get transition as (localtime): June 03, 1973 00:00:00 GMT+2

type: 3, transition time in file:118188000
Add previous offset to get transition as (localtime): September 30, 1973 00:00:00 GMT+1

type: 2, transition time in file:138754800
Add previous offset to get transition as (localtime): May 26, 1974 00:00:00 GMT+2

type: 3, transition time in file:149637600
Add previous offset to get transition as (localtime): September 29, 1974 00:00:00 GMT+1

type: 0, transition time in file:170809200
Add previous offset to get transition as (localtime): June 01, 1975 00:00:00 GMT+2

type: 1, transition time in file:181090800
Add previous offset to get transition as (localtime): September 28, 1975 01:00:00 GMT+1

type: 0, transition time in file:202258800
Add previous offset to get transition as (localtime): May 30, 1976 00:00:00 GMT+2

type: 1, transition time in file:212540400
Add previous offset to get transition as (localtime): September 26, 1976 01:00:00 GMT+1

type: 0, transition time in file:233103600
Add previous offset to get transition as (localtime): May 22, 1977 00:00:00 GMT+2

type: 1, transition time in file:243990000
Add previous offset to get transition as (localtime): September 25, 1977 01:00:00 GMT+1

type: 0, transition time in file:265158000
Add previous offset to get transition as (localtime): May 28, 1978 00:00:00 GMT+2

type: 1, transition time in file:276044400
Add previous offset to get transition as (localtime): October 01, 1978 01:00:00 GMT+1

type: 0, transition time in file:296607600
Add previous offset to get transition as (localtime): May 27, 1979 00:00:00 GMT+2

type: 1, transition time in file:307494000
Add previous offset to get transition as (localtime): September 30, 1979 01:00:00 GMT+1

type: 4, transition time in file:323830800
Add previous offset to get transition as (localtime): April 06, 1980 02:00:00 GMT+2

type: 5, transition time in file:338950800
Add previous offset to get transition as (localtime): September 28, 1980 03:00:00 GMT+1

type: 4, transition time in file:354675600
Add previous offset to get transition as (localtime): March 29, 1981 02:00:00 GMT+2

type: 5, transition time in file:370400400
Add previous offset to get transition as (localtime): September 27, 1981 03:00:00 GMT+1

type: 4, transition time in file:386125200
Add previous offset to get transition as (localtime): March 28, 1982 02:00:00 GMT+2

type: 5, transition time in file:401850000
Add previous offset to get transition as (localtime): September 26, 1982 03:00:00 GMT+1

type: 4, transition time in file:417574800
Add previous offset to get transition as (localtime): March 27, 1983 02:00:00 GMT+2

type: 5, transition time in file:433299600
Add previous offset to get transition as (localtime): September 25, 1983 03:00:00 GMT+1

type: 4, transition time in file:449024400
Add previous offset to get transition as (localtime): March 25, 1984 02:00:00 GMT+2

type: 5, transition time in file:465354000
Add previous offset to get transition as (localtime): September 30, 1984 03:00:00 GMT+1

type: 4, transition time in file:481078800
Add previous offset to get transition as (localtime): March 31, 1985 02:00:00 GMT+2

type: 5, transition time in file:496803600
Add previous offset to get transition as (localtime): September 29, 1985 03:00:00 GMT+1

type: 4, transition time in file:512528400
Add previous offset to get transition as (localtime): March 30, 1986 02:00:00 GMT+2

type: 5, transition time in file:528253200
Add previous offset to get transition as (localtime): September 28, 1986 03:00:00 GMT+1

type: 4, transition time in file:543978000
Add previous offset to get transition as (localtime): March 29, 1987 02:00:00 GMT+2

type: 5, transition time in file:559702800
Add previous offset to get transition as (localtime): September 27, 1987 03:00:00 GMT+1

type: 4, transition time in file:575427600
Add previous offset to get transition as (localtime): March 27, 1988 02:00:00 GMT+2

type: 5, transition time in file:591152400
Add previous offset to get transition as (localtime): September 25, 1988 03:00:00 GMT+1

type: 4, transition time in file:606877200
Add previous offset to get transition as (localtime): March 26, 1989 02:00:00 GMT+2

type: 5, transition time in file:622602000
Add previous offset to get transition as (localtime): September 24, 1989 03:00:00 GMT+1

type: 4, transition time in file:638326800
Add previous offset to get transition as (localtime): March 25, 1990 02:00:00 GMT+2

type: 5, transition time in file:654656400
Add previous offset to get transition as (localtime): September 30, 1990 03:00:00 GMT+1

type: 4, transition time in file:670381200
Add previous offset to get transition as (localtime): March 31, 1991 02:00:00 GMT+2

type: 5, transition time in file:686106000
Add previous offset to get transition as (localtime): September 29, 1991 03:00:00 GMT+1

type: 4, transition time in file:701830800
Add previous offset to get transition as (localtime): March 29, 1992 02:00:00 GMT+2

type: 5, transition time in file:717555600
Add previous offset to get transition as (localtime): September 27, 1992 03:00:00 GMT+1

type: 4, transition time in file:733280400
Add previous offset to get transition as (localtime): March 28, 1993 02:00:00 GMT+2

type: 5, transition time in file:749005200
Add previous offset to get transition as (localtime): September 26, 1993 03:00:00 GMT+1

type: 4, transition time in file:764730000
Add previous offset to get transition as (localtime): March 27, 1994 02:00:00 GMT+2

type: 5, transition time in file:780454800
Add previous offset to get transition as (localtime): September 25, 1994 03:00:00 GMT+1

type: 4, transition time in file:796179600
Add previous offset to get transition as (localtime): March 26, 1995 02:00:00 GMT+2

type: 5, transition time in file:811904400
Add previous offset to get transition as (localtime): September 24, 1995 03:00:00 GMT+1

type: 4, transition time in file:828234000
Add previous offset to get transition as (localtime): March 31, 1996 02:00:00 GMT+2

type: 5, transition time in file:846378000
Add previous offset to get transition as (localtime): October 27, 1996 03:00:00 GMT+1

type: 4, transition time in file:859683600
Add previous offset to get transition as (localtime): March 30, 1997 02:00:00 GMT+2

type: 5, transition time in file:877827600
Add previous offset to get transition as (localtime): October 26, 1997 03:00:00 GMT+1

type: 4, transition time in file:891133200
Add previous offset to get transition as (localtime): March 29, 1998 02:00:00 GMT+2

type: 5, transition time in file:909277200
Add previous offset to get transition as (localtime): October 25, 1998 03:00:00 GMT+1

type: 4, transition time in file:922582800
Add previous offset to get transition as (localtime): March 28, 1999 02:00:00 GMT+2

type: 5, transition time in file:941331600
Add previous offset to get transition as (localtime): October 31, 1999 03:00:00 GMT+1

type: 4, transition time in file:954032400
Add previous offset to get transition as (localtime): March 26, 2000 02:00:00 GMT+2

type: 5, transition time in file:972781200
Add previous offset to get transition as (localtime): October 29, 2000 03:00:00 GMT+1

type: 4, transition time in file:985482000
Add previous offset to get transition as (localtime): March 25, 2001 02:00:00 GMT+2

type: 5, transition time in file:1004230800
Add previous offset to get transition as (localtime): October 28, 2001 03:00:00 GMT+1

type: 4, transition time in file:1017536400
Add previous offset to get transition as (localtime): March 31, 2002 02:00:00 GMT+2

type: 5, transition time in file:1035680400
Add previous offset to get transition as (localtime): October 27, 2002 03:00:00 GMT+1

type: 4, transition time in file:1048986000
Add previous offset to get transition as (localtime): March 30, 2003 02:00:00 GMT+2

type: 5, transition time in file:1067130000
Add previous offset to get transition as (localtime): October 26, 2003 03:00:00 GMT+1

type: 4, transition time in file:1080435600
Add previous offset to get transition as (localtime): March 28, 2004 02:00:00 GMT+2

type: 5, transition time in file:1099184400
Add previous offset to get transition as (localtime): October 31, 2004 03:00:00 GMT+1

type: 4, transition time in file:1111885200
Add previous offset to get transition as (localtime): March 27, 2005 02:00:00 GMT+2

type: 5, transition time in file:1130634000
Add previous offset to get transition as (localtime): October 30, 2005 03:00:00 GMT+1

type: 4, transition time in file:1143334800
Add previous offset to get transition as (localtime): March 26, 2006 02:00:00 GMT+2

type: 5, transition time in file:1162083600
Add previous offset to get transition as (localtime): October 29, 2006 03:00:00 GMT+1

type: 4, transition time in file:1174784400
Add previous offset to get transition as (localtime): March 25, 2007 02:00:00 GMT+2

type: 5, transition time in file:1193533200
Add previous offset to get transition as (localtime): October 28, 2007 03:00:00 GMT+1

type: 4, transition time in file:1206838800
Add previous offset to get transition as (localtime): March 30, 2008 02:00:00 GMT+2

type: 5, transition time in file:1224982800
Add previous offset to get transition as (localtime): October 26, 2008 03:00:00 GMT+1

type: 4, transition time in file:1238288400
Add previous offset to get transition as (localtime): March 29, 2009 02:00:00 GMT+2

type: 5, transition time in file:1256432400
Add previous offset to get transition as (localtime): October 25, 2009 03:00:00 GMT+1

type: 4, transition time in file:1269738000
Add previous offset to get transition as (localtime): March 28, 2010 02:00:00 GMT+2

type: 5, transition time in file:1288486800
Add previous offset to get transition as (localtime): October 31, 2010 03:00:00 GMT+1

type: 4, transition time in file:1301187600
Add previous offset to get transition as (localtime): March 27, 2011 02:00:00 GMT+2

type: 5, transition time in file:1319936400
Add previous offset to get transition as (localtime): October 30, 2011 03:00:00 GMT+1

type: 4, transition time in file:1332637200
Add previous offset to get transition as (localtime): March 25, 2012 02:00:00 GMT+2

type: 5, transition time in file:1351386000
Add previous offset to get transition as (localtime): October 28, 2012 03:00:00 GMT+1

type: 4, transition time in file:1364691600
Add previous offset to get transition as (localtime): March 31, 2013 02:00:00 GMT+2

type: 5, transition time in file:1382835600
Add previous offset to get transition as (localtime): October 27, 2013 03:00:00 GMT+1

type: 4, transition time in file:1396141200
Add previous offset to get transition as (localtime): March 30, 2014 02:00:00 GMT+2

type: 5, transition time in file:1414285200
Add previous offset to get transition as (localtime): October 26, 2014 03:00:00 GMT+1

type: 4, transition time in file:1427590800
Add previous offset to get transition as (localtime): March 29, 2015 02:00:00 GMT+2

type: 5, transition time in file:1445734800
Add previous offset to get transition as (localtime): October 25, 2015 03:00:00 GMT+1

type: 4, transition time in file:1459040400
Add previous offset to get transition as (localtime): March 27, 2016 02:00:00 GMT+2

type: 5, transition time in file:1477789200
Add previous offset to get transition as (localtime): October 30, 2016 03:00:00 GMT+1

type: 4, transition time in file:1490490000
Add previous offset to get transition as (localtime): March 26, 2017 02:00:00 GMT+2

type: 5, transition time in file:1509238800
Add previous offset to get transition as (localtime): October 29, 2017 03:00:00 GMT+1

type: 4, transition time in file:1521939600
Add previous offset to get transition as (localtime): March 25, 2018 02:00:00 GMT+2

type: 5, transition time in file:1540688400
Add previous offset to get transition as (localtime): October 28, 2018 03:00:00 GMT+1

type: 4, transition time in file:1553994000
Add previous offset to get transition as (localtime): March 31, 2019 02:00:00 GMT+2

type: 5, transition time in file:1572138000
Add previous offset to get transition as (localtime): October 27, 2019 03:00:00 GMT+1

type: 4, transition time in file:1585443600
Add previous offset to get transition as (localtime): March 29, 2020 02:00:00 GMT+2

type: 5, transition time in file:1603587600
Add previous offset to get transition as (localtime): October 25, 2020 03:00:00 GMT+1

type: 4, transition time in file:1616893200
Add previous offset to get transition as (localtime): March 28, 2021 02:00:00 GMT+2

type: 5, transition time in file:1635642000
Add previous offset to get transition as (localtime): October 31, 2021 03:00:00 GMT+1

type: 4, transition time in file:1648342800
Add previous offset to get transition as (localtime): March 27, 2022 02:00:00 GMT+2

type: 5, transition time in file:1667091600
Add previous offset to get transition as (localtime): October 30, 2022 03:00:00 GMT+1

type: 4, transition time in file:1679792400
Add previous offset to get transition as (localtime): March 26, 2023 02:00:00 GMT+2

type: 5, transition time in file:1698541200
Add previous offset to get transition as (localtime): October 29, 2023 03:00:00 GMT+1

type: 4, transition time in file:1711846800
Add previous offset to get transition as (localtime): March 31, 2024 02:00:00 GMT+2

type: 5, transition time in file:1729990800
Add previous offset to get transition as (localtime): October 27, 2024 03:00:00 GMT+1

type: 4, transition time in file:1743296400
Add previous offset to get transition as (localtime): March 30, 2025 02:00:00 GMT+2

type: 5, transition time in file:1761440400
Add previous offset to get transition as (localtime): October 26, 2025 03:00:00 GMT+1

type: 4, transition time in file:1774746000
Add previous offset to get transition as (localtime): March 29, 2026 02:00:00 GMT+2

type: 5, transition time in file:1792890000
Add previous offset to get transition as (localtime): October 25, 2026 03:00:00 GMT+1

type: 4, transition time in file:1806195600
Add previous offset to get transition as (localtime): March 28, 2027 02:00:00 GMT+2

type: 5, transition time in file:1824944400
Add previous offset to get transition as (localtime): October 31, 2027 03:00:00 GMT+1

type: 4, transition time in file:1837645200
Add previous offset to get transition as (localtime): March 26, 2028 02:00:00 GMT+2

type: 5, transition time in file:1856394000
Add previous offset to get transition as (localtime): October 29, 2028 03:00:00 GMT+1

type: 4, transition time in file:1869094800
Add previous offset to get transition as (localtime): March 25, 2029 02:00:00 GMT+2

type: 5, transition time in file:1887843600
Add previous offset to get transition as (localtime): October 28, 2029 03:00:00 GMT+1

type: 4, transition time in file:1901149200
Add previous offset to get transition as (localtime): March 31, 2030 02:00:00 GMT+2

type: 5, transition time in file:1919293200
Add previous offset to get transition as (localtime): October 27, 2030 03:00:00 GMT+1

type: 4, transition time in file:1932598800
Add previous offset to get transition as (localtime): March 30, 2031 02:00:00 GMT+2

type: 5, transition time in file:1950742800
Add previous offset to get transition as (localtime): October 26, 2031 03:00:00 GMT+1

type: 4, transition time in file:1964048400
Add previous offset to get transition as (localtime): March 28, 2032 02:00:00 GMT+2

type: 5, transition time in file:1982797200
Add previous offset to get transition as (localtime): October 31, 2032 03:00:00 GMT+1

type: 4, transition time in file:1995498000
Add previous offset to get transition as (localtime): March 27, 2033 02:00:00 GMT+2

type: 5, transition time in file:2014246800
Add previous offset to get transition as (localtime): October 30, 2033 03:00:00 GMT+1

type: 4, transition time in file:2026947600
Add previous offset to get transition as (localtime): March 26, 2034 02:00:00 GMT+2

type: 5, transition time in file:2045696400
Add previous offset to get transition as (localtime): October 29, 2034 03:00:00 GMT+1

type: 4, transition time in file:2058397200
Add previous offset to get transition as (localtime): March 25, 2035 02:00:00 GMT+2

type: 5, transition time in file:2077146000
Add previous offset to get transition as (localtime): October 28, 2035 03:00:00 GMT+1

type: 4, transition time in file:2090451600
Add previous offset to get transition as (localtime): March 30, 2036 02:00:00 GMT+2

type: 5, transition time in file:2108595600
Add previous offset to get transition as (localtime): October 26, 2036 03:00:00 GMT+1

type: 4, transition time in file:2121901200
Add previous offset to get transition as (localtime): March 29, 2037 02:00:00 GMT+2

type: 5, transition time in file:2140045200
Add previous offset to get transition as (localtime): October 25, 2037 03:00:00 GMT+1

我的第 2 次和第 4 次转换比here 列出的要晚一个小时,但几乎其他所有内容看起来都匹配。

【问题讨论】:

    标签: unix timezone


    【解决方案1】:

    “标准时间”是指“冬令时”,而不是“夏令时”或“夏令时”。是的,GMT(松散地;严格地说,UTC)是“时间标准”,但它与您数据中的“isstd”列所指的内容并不完全相同。

    'isstd' 为 0 或 1 的意义在于,欧洲的转换时间(通常)指定为在当前时区的 02:00 发生。

    因此,欧洲/罗马的时钟走了:

    1982-03-28 01:59:59 (UTC+01:00)
    1982-03-28 03:00:00 (UTC+02:00)
    

    据记录,此转换发生在标准时间 02:00(isstd = 1),但这不是 UTC (GMT) 时间;因此,它是您列表中的 0 型转换。相反,在秋天,时钟走了:

    1982-09-26 01:59:59 (UTC+02:00)
    1982-09-26 01:00:00 (UTC+01:00)
    

    据记录,转换发生在转换前的时区 02:00,因此 isstd = 0(但它不是 UTC (GMT) 时间);因此,这是您列表中的第 3 类转换。

    其他组合(类型 1、2、4、5)出现在其他情况下。对于相同的两个转换,您将使用类型 4 条目并将更改时间记录为 01:00 UTC(因为 01:00:00+00:00 与 02:00:00+01:00 相同;并且您将使用类型 5 条目并将更改时间记录为 00:00 UTC(因为 00:00:00+00:00 与 02:00:00+02:00 相同)。请注意此处的切换时间彼此不同。描述中的类似差异适用于类型 1 和 2。

    【讨论】:

    • 感谢您解释它是如何工作的。如果我理解正确,文件中的转换时间并不总是存储为 GMT(不含 DST)。 isstd 和 isgmt 告诉你它们是如何存储的?我想将它们全部转换为 GMT。如果转换时间的类型为 isstd=1 且 isgmt=1,则 trans.时间已经存储为 GMT,对吗?如果 isstd=1 和 isgmt = 0,我会减去转换前本地时间的偏移量吗?如果 isstd=0 且 isgmt = 1,是否假定 DST 只有 1 小时?所以我会从过渡时间减去 1 小时将其转换为 GMT(没有 DST)?再次感谢!
    • 我什至会说“转换时间通常不存储为 GMT”。考虑比欧洲/罗马更远离 UTC 的时区。例如,America/Los_Angeles 的切换时间为 02:00,但这是本地时间,而不是 UTC 时间。我相信,但是自从我上次查看代码以来已经有好几年了,isstd 和 isgmt 告诉你时间是如何存储的。您可以展开表格以显示存储的转换时间。我认为在没有相反指示的情况下,跳跃被假定为一个小时;只有历史区域有不同的价值,AFAIK。
    • “标准时间”指的是“冬季时间”……除非你在俄罗斯:timeanddate.com/news/time/russia-winter-time.html ;-)
    • @JonathanLeffler 解释很深入,但您说第一种类型是 0 型。实际上它是 4 型,如最初的帖子所示。这对您的答案有何影响?
    • @Jason:我必须尽快了解 Olson 数据库格式,自从我回答这个问题以来,它已经被调整过了。唯一快速的答案是“我不知道”。我需要一些时间。
    【解决方案2】:

    我打算编辑我​​的原始帖子,但它说它太长了:

    更新:

    我认为我的数据是正确的,TimeAndDate.com 有一个小错误。

    在我的测试中,我专注于罗马的前 2 个过渡。

    我的数据是:

    类型:0,转换时间在 文件:-1690851600

    添加上一个偏移量 获取本地过渡时间:6月03日, 1916 00:00:00 新时区为 GMT+2

    类型:1,转换时间在 文件:-1680483600

    添加上一个偏移量 获取本地过渡时间:10 月 01, 1916 01:00:00 新时区是 格林威治标准时间+1

    TimeAndDate的数据显示:

    1.) 1916 年 6 月 3 日星期六晚上 11:59:59

    1916 年 6 月 4 日星期日 12:00:00 午夜 → 凌晨 1:00:00 +1h UTC+2h CEST DST 开始

    2.) 1916 年 9 月 30 日星期六 11:59:59 下午

    12:00:00 午夜 → 11:00:00 PM 没有 UTC+1h CET DST 结束

    我将计算机的时区和当地时间设置为与罗马匹配。 然后,我运行了以下代码:

    time_t rome_ts;
    struct tm * rome_info;
    char rome_buffer[75];
    
    printf("My first transition:\n");
    
    rome_ts = -1690851601;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n");
    
    rome_ts = -1690851600;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n");
    
    rome_ts = -1690851599;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n\n\n");
    
    
    printf("TimeandDate.com's first transition:\n");
    
    rome_ts = -1690768801;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n");
    
    rome_ts = -1690768800;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n");
    
    rome_ts = -1690768799;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n\n\n");
    
    
    printf("My second transition:\n");
    
    rome_ts = -1680483601;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n");
    
    rome_ts = -1680483600;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n");
    
    rome_ts = -1680483599;
    rome_info = localtime(&rome_ts);
    printf("Timestamp: %ld\n",rome_ts);
    strftime(rome_buffer,75,"%A %B %d, %Y %H:%M:%S %Z",rome_info);
    printf("%s, dst? = %d\n",rome_buffer,rome_info->tm_isdst);
    printf("\n\n\n");
    

    输出显示 localtime() 与我的转换时间一致:

    我的第一次转换:时间戳:

    -1690851601 1916 年 6 月 2 日星期五 23:59:59 CET,夏令时? = 0

    时间戳:-1690851600 六月星期六 1916 年 03 月 01:00:00 CEST,夏令时? = 1

    时间戳:-1690851599 六月星期六 1916 年 03 月 01:00:01 CEST,夏令时? = 1

    TimeandDate.com 的第一次转换:

    时间戳:-1690768801 六月星期六 1916 年 1 月 3 日 23:59:59 CEST,夏令时? = 1

    时间戳:-1690768800 6 月 4 日星期日, 1916 00:00:00 CEST,夏令时? = 1

    时间戳:-1690768799 6 月 4 日星期日, 1916 00:00:01 CEST,夏令时? = 1

    我的第二次转换:时间戳:

    -1680483601 1916 年 10 月 1 日星期日 00:59:59 CEST,夏令时? = 1

    时间戳:-1680483600 十月星期日 1916 年 01 月 00:00:00 CET,夏令时? = 0

    时间戳:-1680483599 十月星期日 1916 年 1 月 1 日 00:00:01 CET,夏令时? = 0

    【讨论】:

      猜你喜欢
      • 2019-11-24
      • 1970-01-01
      • 1970-01-01
      • 2014-10-28
      • 2012-03-03
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多