centos 6.5 查看时区和设置时区

时间:2023-03-09 23:29:32
centos 6.5 查看时区和设置时区

centos6.x 和centos7.x在时区方面有点差距,本文是针对centos6.x进行介绍。

其实在我的一个博文里,在安装系统的时候就可以进行时区的设置,本文介绍的是用命令进行时区查看和设置。

>>提君博客原创  http://www.cnblogs.com/tijun/  <<

使用date命令查看时区

[root@ltt1 ~]# date -R
Thu, Sep :: +

我们国家的东八区(+0800)

查看clock系统配置文件

[root@ltt1 ~]# cat /etc/sysconfig/clock
ZONE="Asia/Shanghai"

我的系统设置的时区为Asia/Shanghai,也就是我们国家的东八区(+0800)。

下面介绍设置时区的一种方式。

使用tzselect设置时区


[root@ltt1 sysconfig]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
) Africa
) Americas
) Antarctica
) Arctic Ocean
) Asia
) Atlantic Ocean
) Australia
) Europe
) Indian Ocean
) Pacific Ocean
) none - I want to specify the time zone using the Posix TZ format.
#?
Please select a country.
) Afghanistan ) Israel ) Palestine
) Armenia ) Japan ) Philippines
) Azerbaijan ) Jordan ) Qatar
) Bahrain ) Kazakhstan ) Russia
) Bangladesh ) Korea (North) ) Saudi Arabia
) Bhutan ) Korea (South) ) Singapore
) Brunei ) Kuwait ) Sri Lanka
) Cambodia ) Kyrgyzstan ) Syria
) China ) Laos ) *
) Cyprus ) Lebanon ) Tajikistan
) East Timor ) Macau ) Thailand
) Georgia ) Malaysia ) Turkmenistan
) * ) * ) United Arab Emirates
) India ) Myanmar (Burma) ) Uzbekistan
) Indonesia ) Nepal ) Vietnam
) Iran ) Oman ) Yemen
) Iraq ) Pakistan
#?
Please select one of the following time zone regions.
) Beijing Time
) * Time
#? The following information has been given: China
Beijing Time Therefore TZ='Asia/Shanghai' will be used.
Local time is now: Thu Sep :: CST .
Universal Time is now: Wed Sep :: UTC .
Is the above information OK?
) Yes
) No
#? You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again. Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai

根据提示一步一步选择就可以。

提君博客原创

>>提君博客原创  http://www.cnblogs.com/tijun/  <<

注意:上面最后的几行的说明,大概意思是说,tzselect命令只是输出一个标准的TZ写法,并不生效,你还需要将这个TZ放到你的home目录下的.profile文件里

如:TZ='Asia/Shanghai'; export TZ,同时还有注销再重新登录系统,才可设置永久生效。

下面亲测进行检验一下

我当前时区和时间

[root@ltt1 ~]# date -R;cat /etc/sysconfig/clock
Thu, Sep :: +
ZONE="Asia/Shanghai"

tzselect设置一个其他的时区,只给出个结果,一些步骤不再贴出

提君博客原创

The following information has been given:

    Anguilla

Therefore TZ='America/Anguilla' will be used.
Local time is now: Wed Sep :: AST .
Universal Time is now: Wed Sep :: UTC .
Is the above information OK?
) Yes
) No
#? You can make this change permanent for yourself by appending the line
TZ='America/Anguilla'; export TZ
to the file '.profile' in your home directory; then log out and log in again. Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
America/Anguilla

追加

[root@ltt1 ~]# vi /etc/profile
TZ='America/Anguilla'; export TZ
[root@ltt1 ~]# source /etc/profile

结果

[root@ltt1 ~]# date -R
Wed, Sep :: -
[root@ltt1 ~]# cat /etc/sysconfig/clock
ZONE="Asia/Shanghai"

额,可以看到 由 +0800  变成了 -0400

提君博客原创

说明成功了,就是文件内容没有更改,目前不知是什么原因。

>>提君博客原创  http://www.cnblogs.com/tijun/  <<