- 工信部备案号 滇ICP备05000110号-1
- 滇公安备案 滇53010302000111
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
首先我同步了一下时间,发现同步之后时间还是不对。
ntpdate cn.pool.ntp.org
怀疑自己看错了,然后输入date查看时间,发现确实不是看错了,而是真的不对。于是我想到是时区不对。
[root@rico ~]# date -R Sat, 10 Nov 2018 17:06:18 +0000
仔细想了一下,我是处于东八区,时间应该是+0800,而我这里是+0000了,
为了求证,我决定cat /etc/sysconfig/clock看一下,输出如下
[root@rico ~]# cat /etc/sysconfig/clock ZONE="UTC"
所以需要改一下,于是使用tzselect进行更改。
[root@rico ~]# tzselect
#? 5
#? 9
#? 1
#? 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.
大概意思是说,tzselect命令只是输出一个标准的TZ写法,并不生效,你还需要将这个TZ放到你的.profile文件里,然后刷新一下这个文件生效
于是接下来我们编辑文件
[root@rico ~]# vim /etc/profile
在文件的末尾另起一行加上
TZ='Asia/Shanghai'; export TZ
然后保存退出,接下来重新加载一下
[root@rico ~]# source /etc/profile
进行验证测试
[root@rico ~]# date
Sun Nov 11 01:32:40 CST 2018
[root@rico ~]# date -R
Sun, 11 Nov 2018 01:36:25 +0800
好了,大功告成!
更改时区的关键就是:在/etc/profile里面写上TZ='Asia/Shanghai'; export TZ ,然后重新加载使生效
我们之所以要去操作这个,是为了确保写在文件里面的写法是标准的,若是能肯定怎么写,直接写上这句就可以。
若是时区对了,时间不对,重新同步一下时间就好。
[root@rico ~]# ntpdate cn.pool.ntp.org
将系统时间写入硬件时间
# hwclock --systohc
接下来附上我操作时候的记录
[root@rico ~]# ntpdate cn.pool.ntp.org 10 Nov 17:05:24 ntpdate[1824]: the NTP socket is in use, exiting [root@rico ~]# date Sat Nov 10 17:05:32 UTC 2018 [root@rico ~]# date -R Sat, 10 Nov 2018 17:06:18 +0000 [root@rico ~]# cat /etc/sysconfig/clock ZONE="UTC" [root@rico ~]# 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:Sun Nov 11 01:08:22 CST 2018. Universal Time is now:Sat Nov 10 17:08:22 UTC 2018. 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 [root@rico ~]# vim /etc/profile [root@rico ~]# source /etc/profile [root@rico ~]# date Sun Nov 11 01:32:40 CST 2018 [root@rico ~]# date -R Sun, 11 Nov 2018 01:36:25 +0800
售前咨询
售后咨询
备案咨询
二维码
TOP