【发布时间】: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' 函数输出。
-
啊!我想我现在明白你的问题了。我的回答一定对你毫无意义。我正在改变我的答案,希望现在能回答你的问题......