我通过将zoneinfo文件复制到/ etc / localtime,在我的Linux机器上将时区设置为GMT 6,但是date命令仍然将时间显示为UTCtime-6.任何人都可以向我解释这种行为吗?
我假设date命令应该显示UTCtime 6时间.以下是我要遵循的步骤:
date
Wed Jan 22 17:29:01 IST 2014
date -u
Wed Jan 22 11:59:01 UTC 2014
cp /usr/share/zoneinfo/Etc/GMT+6 /etc/localtime
date
Wed Jan 22 05:59:21 GMT+6 2014
date -u
Wed Jan 22 11:59:01 UTC 2014
解决方法:
红帽发行
如果您使用的是Red Hat这样的发行版,那么您复制文件的方法几乎是可以接受的.
注意:如果您正在寻找与发行版无关的解决方案,这也适用于Debian,但如果您只需要关注Debian计算机,下面有更简单的方法.
$ls /usr/share/zoneinfo/
Africa/ CET Etc/ Hongkong Kwajalein Pacific/ ROK zone.tab
America/ Chile/ Europe/ HST Libya Poland Singapore Zulu
Antarctica/ CST6CDT GB Iceland MET Portugal Turkey
Arctic/ Cuba GB-Eire Indian/ Mexico/ posix/ UCT
Asia/ EET GMT Iran MST posixrules Universal
Atlantic/ Egypt GMT0 iso3166.tab MST7MDT PRC US/
Australia/ Eire GMT-0 Israel Navajo PST8PDT UTC
Brazil/ EST GMT+0 Jamaica NZ right/ WET
Canada/ EST5EDT Greenwich Japan NZ-CHAT ROC W-SU
我建议链接到它而不是复制.
$sudo unlink /etc/localtime
$sudo ln -s /usr/share/zoneinfo/Etc/GMT+6 /etc/localtime
现在日期显示不同的时区:
$date -u
Thu Jan 23 05:40:31 UTC 2014
$date
Wed Jan 22 23:40:38 GMT+6 2014
Ubuntu / Debian发行版
要更改这些发行版中的任何一个的时区,您可以使用此命令:
$sudo dpkg-reconfigure tzdata
$sudo dpkg-reconfigure tzdata
Current default time zone: 'Etc/GMT-6'
Local time is now: Thu Jan 23 11:52:16 GMT-6 2014.
Universal Time is now: Thu Jan 23 05:52:16 UTC 2014.
现在,当我们检查出来时:
$date -u
Thu Jan 23 05:53:32 UTC 2014
$date
Thu Jan 23 11:53:33 GMT-6 2014
注意:Ubuntu 14.04及更高版本中还有一个选项,只需一个命令(来源:Ask Ubuntu – setting timezone from terminal):
$sudo timedatectl set-timezone Etc/GMT-6
关于“Etc / GMT 6”的使用
Zones like Etc/GMT+6 are intentionally reversed for backwards compatibility with POSIX standards. See the comments in 07003.
You should almost never need to use these zones. Instead you should be using a fully named time zone like America/New_York or Europe/London or whatever is appropriate for your location. Refer to the list 07004.
标签:linux,timezone,date,time
来源: https://codeday.me/bug/20190808/1621463.html