0002_20190328_Centos修改系统时间

一.   设置修改时间:

  1. 查看当前时区:
[root@localhost bin]# date -R

Thu, 28 Mar 2019 11:31:19 +0800

  2. 查看时间和日期:

[root@localhost bin]# date

2019年 03月 28日 星期四 11:32:38 CST

  3. 查看硬件时间:

[root@localhost bin]# hwclock --show

  4. 设置当前日期:

[root@localhost bin]# date -s 2019-3-28

  5. 设置硬件时间:

[root@localhost bin]#  hwclock --set --date="2019-3-28 11:41:05"

  6.设置当前时间:

[root@localhost bin]# date -s 11:34:28

2019年 03月 28日 星期四 11:34:28 CST

  7.将当前时间写入BIOS, 防止重启失效

[root@localhost bin]# hwclock –w

  8. 替换系统时区时间:

  设置中国时区使用重庆时间

[root@localhost bin]# cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime 

二.   时间同步:

  1. 系统和硬件时间相互同步:
[root@localhost bin]#  hwclock –hctosys  #硬件时间写入到系统时间

[root@localhost bin]#  hwclock –systohc  #软件时间写入到硬件时间

  2. 同步网络上的时间:

a) 同步网络时间需要安装ntpdate时间同步服务软件;
b) 检查本机是否安装ntpdate

[root@localhost ~]# yum list installed | grep ntpdate     
[root@localhost ~]# rpm -qa |grep ntpd*

c) 使用yum安装ntpdate

[root@localhost ~]# yum install -y ntpdate

d) 选择服务器同步时间, 可用的服务器有下面几个:
time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org
[root@localhost ~]# ntpdate time.nist.gov  #同步时间服务器

三.   添加定时任务, 同步时间:

a)         每隔一小时同步网络时间

[root@localhost ~]# #* */1 * * * root ntpdatetime.nuri.net;hwclock -w
原文地址:https://www.cnblogs.com/wxylog/p/10614038.html