欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

修改CentOS服务器时间为北京时间

程序员文章站 2022-05-26 12:10:44
1. 购买了VPS,CentOS系统,发现服务器时间与北京时间往往不一致,存在时差。 2. 可以执行tzselect命令按提示更换时区,依次选择5 Asia,9 China,1 Beijing Time。 3. 将 这行添加到/etc/profile(所有用户生效)或者~/.bash_profile ......
  1. 购买了vps,centos系统,发现服务器时间与北京时间往往不一致,存在时差。
[clive@server workspace]$ date
2018年 05月 30日 星期三 02:02:47 utc
  1. 可以执行tzselect命令按提示更换时区,依次选择5-asia,9-china,1-beijing time。
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) *
10) cyprus        27) lebanon           44) tajikistan
11) east timor        28) macau         45) thailand
12) georgia       29) malaysia          46) turkmenistan
13) *         30) *          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) * time
#? 1

the following information has been given:

    china
    beijing time

therefore tz='asia/shanghai' will be used.
local time is now:  wed may 30 10:04:16 cst 2018.
universal time is now:  wed may 30 02:04:16 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
  1. tz='asia/shanghai'; export tz这行添加到/etc/profile(所有用户生效)或者~/.bash_profile(当前用户生效)
  2. 退出重新登录即可,也可执行source /etc/profilesource ~/.bash_profile立即生效
  3. 这时候再执行date查看日期就可以发现时区改为北京时间啦。
[clive@server workspace]$ date
2018年 05月 30日 星期三 10:07:11 cst