linux modify time and time zone

    There are two linux system time, one is the hardware time, that is, the BIOS time, which is the time we see when we set the CMOS, and the other is the system time, which is the kernel time of the linux system. When Linux starts, the system kernel will read the hardware clock settings, and then the system clock will operate independently of the hardware. Sometimes we find that the system clock and the hardware clock are inconsistent, so time synchronization needs to be performed.

method one

1. date View/set the system time

1、将日期设置为2017年11月3日
[root@linux-node ~]# date -s 11/03/17 2、将时间设置为14点20分50秒 [root@linux-node ~]# date -s 14:20:50 3、将时间设置为2017年11月3日14点16分30秒(MMDDhhmmYYYY.ss) [root@linux-node ~]# date 1103141617.30


2. hwclock/clock View/set hardware time

1、查看系统硬件时钟
[root@linux-node ~]# hwclock  --show 或者
[root@linux-node ~]# clock --show 2、设置硬件时间 [root@linux-node ~]# hwclock --set --date="11/03/17 14:55" (月/日/年时:分:秒) 或者 [root@linux-node ~]# clock --set --date="11/03/17 14:55" (月/日/年时:分:秒)


3. Synchronization system and hardware clock

[root@linux-node ~]# hwclock --hctosys 或者
[root@linux-node ~]# clock --hctosys  
备注:hc代表硬件时间,sys代表系统时间,以硬件时间为基准,系统时间找硬件时间同步


[root@linux-node ~]# hwclock --systohc或者 [root@linux-node ~]# clock --systohc 备注:以系统时间为基准,硬件时间找系统时间同步

Method Two

Time zone setting is implemented with the tzselect command. However, the time zone selected by setting the TZ environment variable through the tzselect command needs to be added to the .profile file.

1. tzselect command execution

执行tzselect命令 --> 选择Asia --> 选择China --> 选择east China - Beijing, Guangdong, Shanghai, etc-->然后输入1。

After executing the tzselect command to select the time zone, the time zone has not changed, but at the end of the command, you are prompted that you can execute TZ='Asia/Shanghai'; export TZ  and add this command to .profile, then log out and log in again. 

Second, modify the configuration file to modify the time zone

[root@linux-node ~]# echo "ZONE=Asia/Shanghai" >> /etc/sysconfig/clock         
[root@linux-node ~]# rm -f /etc/localtime
#链接到上海时区文件 [root@linux-node ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

After performing the above process, restart the machine and you can see that the time zone has been changed.

Remark:

在centos7中设置时区的命令可以通过 timedatectl 命令来实现
[root@linux-node ~]# timedatectl set-timezone Asia/Shanghai

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324949458&siteId=291194637