from http://blog.itnmg.net/centos-7-time-date/

yum install ntp //安装ntp服务
systemctl enable ntpd //开机启动服务
systemctl start ntpd //启动服务
timedatectl set-timezone Asia/Shanghai //更改时区
timedatectl set-ntp yes //启用ntp同步
ntpq -p //同步时间

其它内容粘贴如下:

CentOS 7 设置日期和时间

在CentOS 6版本,时间设置有date、hwclock命令,从CentOS 7开始,使用了一个新的命令timedatectl。

一、基本概念

1.1 GMT、UTC、CST、DST 时间

(1) UTC

整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。

(2) GMT

格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)

(3) CST

中国标准时间 (China Standard Time)

Default
GMT + 8 = UTC + 8 = CST
1
GMT + 8 = UTC + 8 = CST

(4) DST

夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时钟拨快一小时,以提早日光的使用。(中国不使用)

1.2 硬件时钟和系统时钟

(1) 硬件时钟

RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会继续运行。仅保存日期时间数值,无法保存时区和夏令时设置。

(2) 系统时钟

一般在服务器启动时复制RTC时间,之后独立运行,保存了时间、时区和夏令时设置。

二、timedatectl 命令

2.1 读取时间

Shell
timedatectl //等同于 timedatectl status
1
timedatectl //等同于 timedatectl status

2.2 设置时间

Shell
timedatectl set-time "YYYY-MM-DD HH:MM:SS"
1
timedatectl set-time "YYYY-MM-DD HH:MM:SS"

2.3 列出所有时区

Shell
timedatectl list-timezones
1
timedatectl list-timezones

2.4 设置时区

Shell
timedatectl set-timezone Asia/Shanghai
1
timedatectl set-timezone Asia/Shanghai

2.5 是否NTP服务器同步

Shell
timedatectl set-ntp yes //yes或者no
1
timedatectl set-ntp yes //yes或者no

2.6 将硬件时钟调整为与本地时钟一致

Shell
timedatectl set-local-rtc 1
hwclock --systohc --localtime //与上面命令效果一致
1
2
timedatectl set-local-rtc 1
hwclock --systohc --localtime //与上面命令效果一致

注意 硬件时钟默认使用UTC时间,因为硬件时钟不能保存时区和夏令时调整,修改后就无法从硬件时钟中读取出准确标准时间,因此不建议修改。修改后系统会出现警告。

2.6 硬件时间设置成 UTC:

Shell
timedatectl set-local-rtc 1
hwclock --systohc --utc //与上面命令效果一致
1
2
timedatectl set-local-rtc 1
hwclock --systohc --utc //与上面命令效果一致

三、设置系统时间为中国时区并启用NTP同步

Shell
yum install ntp //安装ntp服务
systemctl enable ntpd //开机启动服务
systemctl start ntpd //启动服务
timedatectl set-timezone Asia/Shanghai //更改时区
timedatectl set-ntp yes //启用ntp同步
ntpq -p //同步时间
1
2
3
4
5
6
yum install ntp //安装ntp服务
systemctl enable ntpd //开机启动服务
systemctl start ntpd //启动服务
timedatectl set-timezone Asia/Shanghai //更改时区
timedatectl set-ntp yes //启用ntp同步
ntpq -p //同步时间

如需更改时间服务器, 修改 /etc/ntp.conf 文件中的服务器地址 server 即可.

CentOS 7 时间, 日期设置 (含时间同步)的更多相关文章

  1. CentOS 7系统中的时间日期设置

    修改 CentOS 7系统中的时间日期设置 timedatectl set-ntp no timedatectl timedatectl set-time 2022-06-04 timedatectl ...

  2. 如何让linux时间与internet时间同步(centos)

    笔者在使用linux时(虚拟机),经常会发现使用一段时间后,linux时间和我的宿主机(真实机)的时间不一致,而宿主机的时间确实是internet时间,安装linux时选择的时区也是Asia/Shan ...

  3. CentOS 同步时间

    来源:http://www.ctusky.com/16/0497/ 用date查看系统当前时间,date -R 可查看时区. CentOS 同步时间由ntp服务提供,可以用"yum inst ...

  4. CentOS系统时间修改

    1. 实体机器上安装CentOS $date -s '2015-03-03 13:34:00' 2. 虚拟机上安装的CentOS #查看系统时间和硬件时间 date hwclock --show #设 ...

  5. centos7设置系统时间与网络时间同步

    Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC). 系统时间:指当前Linux Kernel中的时间. 硬件时间:主板上有电池供电的时 ...

  6. CentOS同步时间

    用date查看系统当前时间,date -R 可查看时区. CentOS 同步时间由ntp服务提供,可以用"yum install ntp -y"安装. 装完后运行命令 ntpdat ...

  7. ubuntu设置系统时间与网络时间同步

    ubuntu设置系统时间与网络时间同步   Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC).   系统时间:指当前Linux Ker ...

  8. ubuntu设置系统时间与网络时间同步和时区

    Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC). 系统时间:指当前Linux Kernel中的时间. 硬件时间:主板上有电池供电的时 ...

  9. Centos 修改时间地区及NTP同步北京时间

    在我们使用CentOS系统的时候,也许时区经常会出现问题,有时候改完之后还是会出错,下面我们就来学习一种方法来改变这个状况.如果没有安装,而你使用的是 CentOS系统 那使用命令 yum insta ...

随机推荐

  1. bytes和str的区别与转换

    bytes和str的区别 1.英文 b'alex'的表现形式与str没什么两样 2.中文 b'\xe4\xb8\xad'这是一个汉字在utf-8的bytes表现形式 3.中文 b'\xce\xd2'这 ...

  2. 在powerDesigner中通过SQL生成pdm

    在项目需求分析的阶段,通常需要画数据库表的pdm图.有时候会直接画pdm来设计表,有时候是通过其他方式,如用纸和笔去画……当数据库中的表已经建立好了,怎么把数据库中的表导成SQL形式,然后生成pdm图 ...

  3. js常用校验

    //验证金钱数字obj.regexMoney = function (money) { var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)| ...

  4. [DPDK] 转发 DPDK分析

    前半部分,对于背景和需求的分析,写的相当好啊! 原文地址:https://www.jianshu.com/p/0ff8cb4deaef 背景分析 前10年中,网络程序性能优化的目标主要是为了解决C10 ...

  5. [administrative][CentOS] 新装系统时如何正确精准的选择基础环境和软件包

    出于不同的目的,在进行全新CentOS安装的时候,我们到底应该如何作出选择. 是mininal,base server, base web server, 还是啥? 答案在这里: https://ac ...

  6. jquery-- json字符串没有自动包装为 json对象

    jquery 的一个坑 页面使用 ajax ,回调函数中获取后端返回的 json 格式数据(ajax 未显式指定返回值类型),后端controller方法标注 @ResponseBody 并返回一个 ...

  7. LeetCode 872 Leaf-Similar Trees 解题报告

    题目要求 Consider all the leaves of a binary tree.  From left to right order, the values of those leaves ...

  8. Python创建第一个django应用

    在helloworld工程的基础上,我们准备创建第一个基于web的django应用,把这个应用名字命名为Guest   1.首先,是如何创建这个应用包,当然第一选择我们可以进入到cmd中,执行如下命令 ...

  9. 理解Hbase和BigTable(转)

    add by zhj: 这篇文章写的通俗易懂,介绍了HBase最重要的几点特性. 英文原文:https://dzone.com/articles/understanding-hbase-and-big ...

  10. css三种样式表写法

    css三种样式表:1.内嵌样式表: <head>  <style type="text/css">   样式表写法  </style> < ...