gpt4 book ai didi

linux - 为什么具有相同 UTC 偏移量的两个时区的时间戳不同?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:46:41 25 4
gpt4 key购买 nike

这是一个例子:

root@linux:~# timedatectl 
Local time: Thu 2016-03-31 08:33:23 CEST
Universal time: Thu 2016-03-31 06:33:23 UTC
RTC time: n/a
Time zone: Africa/Ceuta (CEST, +0200)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2016-03-27 01:59:59 CET
Sun 2016-03-27 03:00:00 CEST
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2016-10-30 02:59:59 CEST
Sun 2016-10-30 02:00:00 CET


root@linux:~# echo $string
1970 01 01 0 0 0

root@linux:~# awk -v str="$string" 'BEGIN {print mktime(str)}'
0


root@linux:~# timedatectl set-timezone Europe/Berlin
root@linux:~# timedatectl
Local time: Thu 2016-03-31 08:59:01 CEST
Universal time: Thu 2016-03-31 06:59:01 UTC
RTC time: n/a
Time zone: Europe/Berlin (CEST, +0200)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2016-03-27 01:59:59 CET
Sun 2016-03-27 03:00:00 CEST
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2016-10-30 02:59:59 CEST
Sun 2016-10-30 02:00:00 CET


root@linux:~# echo $string
1970 01 01 0 0 0

root@linux:~# awk -v str="$string" 'BEGIN {print mktime(str)}'
-3600

2 个问题:为什么欧洲/柏林时区的 mktime 输出(当输入 1970-01-01T00:00:00 时)是 -1 小时?

最佳答案

timedatectl(显然)显示对当前设置的时区有效的当前时区规则。但是,在同一时区内,时区规则会随着时间的推移而变化。

截至今天,Africa/Ceuta 和 Europe/Berlin 具有相同的 UTC 偏移量,并遵循完全相同的夏令时规则。但他们并不总是这样做。

在 1970-01-01 Africa/Ceuta 使用了 0:00:00 UTC 偏移并且没有使用夏令时。

在 1970-01-01 Europe/Berlin 使用 1:00:00 UTC 偏移并且没有使用夏令时。

直到 1986-03-30 01:00:00 UTC,Africa/Ceuta 和 Europe/Berlin 才采用相同的规则。您的计算机知道此历史记录,并在为 1986 年 3 月 30 日之前的日期在 UTC 和本地时间之间进行转换时准确反射(reflect)它。

关于linux - 为什么具有相同 UTC 偏移量的两个时区的时间戳不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36328613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com