centos 6.5 查看时区和设置时区
centos6.x 和centos7.x在时区方面有点差距,本文是针对centos6.x进行介绍。
其实在我的一个博文里,在安装系统的时候就可以进行时区的设置,本文介绍的是用命令进行时区查看和设置。
>>提君博客原创 http://www.cnblogs.com/tijun/ <<
使用date命令查看时区
[root@ltt1 ~]# date -R Thu, 28 Sep 2017 00:31:54 +0800
我们国家的东八区(+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. 1) Africa 2) Americas 3) Antarctica 4) Arctic Ocean 5) Asia 6) Atlantic Ocean 7) Australia 8) Europe 9) Indian Ocean 10) Pacific Ocean 11) none - I want to specify the time zone using the Posix TZ format. #? 5 Please select a country. 1) Afghanistan 18) Israel 35) Palestine 2) Armenia 19) Japan 36) Philippines 3) Azerbaijan 20) Jordan 37) Qatar 4) Bahrain 21) Kazakhstan 38) Russia 5) Bangladesh 22) Korea (North) 39) Saudi Arabia 6) Bhutan 23) Korea (South) 40) Singapore 7) Brunei 24) Kuwait 41) Sri Lanka 8) Cambodia 25) Kyrgyzstan 42) Syria 9) China 26) Laos 43) Taiwan 10) Cyprus 27) Lebanon 44) Tajikistan 11) East Timor 28) Macau 45) Thailand 12) Georgia 29) Malaysia 46) Turkmenistan 13) Hong Kong 30) Mongolia 47) United Arab Emirates 14) India 31) Myanmar (Burma) 48) Uzbekistan 15) Indonesia 32) Nepal 49) Vietnam 16) Iran 33) Oman 50) Yemen 17) Iraq 34) Pakistan #? 9 Please select one of the following time zone regions. 1) Beijing Time 2) Xinjiang Time #? 1 The following information has been given: China Beijing Time Therefore TZ='Asia/Shanghai' will be used. Local time is now: Thu Sep 28 00:10:57 CST 2017. Universal Time is now: Wed Sep 27 16:10:57 UTC 2017. Is the above information OK? 1) Yes 2) No #? 1 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, 28 Sep 2017 00:46:39 +0800 ZONE="Asia/Shanghai"
tzselect设置一个其他的时区,只给出个结果,一些步骤不再贴出
The following information has been given: Anguilla Therefore TZ='America/Anguilla' will be used. Local time is now: Wed Sep 27 12:48:20 AST 2017. Universal Time is now: Wed Sep 27 16:48:20 UTC 2017. Is the above information OK? 1) Yes 2) No #? 1 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, 27 Sep 2017 13:01:30 -0400 [root@ltt1 ~]# cat /etc/sysconfig/clock ZONE="Asia/Shanghai"
额,可以看到 由 +0800 变成了 -0400
说明成功了,就是文件内容没有更改,目前不知是什么原因。
>>提君博客原创 http://www.cnblogs.com/tijun/ <<