Press "Enter" to skip to content

Linux system change timezone/date/time

一般来说, CentOS系统时间不对都是因为时区不准确, 因此绝大多数情况下只要将时区修改正确即可, 不需要使用date -s的命令单独修改时间.

# Manually change, NOT RECOMMEND!
date -s 04/13/2013                                   # 修改为2013年4月13日
date -s 17:30:00                                     # 修改为17:30#]

# RECOMMEND
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime     # 修改时区为东八区
sudo cp /usr/share/zoneinfo/America/Chicago /etc/localtime   # Change to US Central Time

hwclock -w                         # 修改完成以后将日期时间写入BIOS, 避免重启失效

System Service

Ubuntu 16.04 以后的系统使用 timedatectl/timesyncd(属于systemd的一部分)取代了 ntpdate/ntp. systemd-timesyncd是一个轻量级的时间同步服务.

sudo systemctl status systemd-timesyncd    # 查看时间服务

timedatectl                                # 查看当前时间

# 修改时间方法1(Gui方式)
sudo dpkg-reconfigure tzdata                   #选择Asia–Hong Kong即可

# 修改时间方法2(shell命令方式)
sudo timedatectl list-timezones | grep Asia    #查看亚洲时区
sudo timedatectl set-timezone Asia/Hong_Kong   #设置时区

补充知识

下面是一些可能有用的命令

sudo ntpd -gq    # 使用 ntp 的方式同步时间(不适用Ubuntu系统)

hwclock -r   #查看hardware时间

sudo hwclock -w --systohc   # set the hardware clock from the current system time

为什么ntp服务已经运行, 系统时间仍是错误的?(Ubuntu)

One Comment

  1. Jason 2014-02-04

    上面的方法是管用的,但系统一旦重启,时间又会变回去,考虑 VPS 重启后可能会被强制同步时间,因此最好在 /etc/rc.local 中加入:
    ntpdate us.pool.ntp.org

Leave a Reply to Jason Cancel reply

Your email address will not be published. Required fields are marked *