【问题标题】:why timestamps for two timezones with the same UTC offset are different?为什么具有相同 UTC 偏移量的两个时区的时间戳不同?
【发布时间】:2016-07-19 14:58:54
【问题描述】:

这是一个例子:

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 小时?

【问题讨论】:

  • 您的标题提出的问题与您在问题中打印的数据相矛盾。我在您的输出中没有看到不同的当地时间。
  • @Howard,是的,你是对的,为了正确,我需要将单词 'local time' 更改为 'timestamps' 作为 'mktime' 函数输出。
  • 啊!我想我现在明白你的问题了。我的回答一定对你毫无意义。我正在改变我的答案,希望现在能回答你的问题......

标签: linux time timezone


【解决方案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,非洲/休达和欧洲/柏林才采用相同的规则。您的计算机知道此历史记录,并在 UTC 和 1986-03-30 之前日期的本地时间之间进行转换时准确地反映它。

【讨论】:

    【解决方案2】:

    它们在不同的日期更改为夏季和冬季时间,这就是为什么即使它们具有相同的 UTC 偏移时间也可能不同

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-04
      • 2016-09-05
      • 2012-02-04
      • 2013-07-16
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      相关资源
      最近更新 更多