linux est 时间,Linux中的时区设置

我通过将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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值