CentOS 7 设置日期和时间 timedatectl
CentOS 7 设置日期和时间
在CentOS 6版本,时间设置有date、hwclock命令,从CentOS 7开始,使用了一个新的命令timedatectl。
timedatectl
[root@ls236 ~]# timedatectl
Local time: 日 2022-06-05 00:40:37 CST
Universal time: 六 2022-06-04 16:40:37 UTC
RTC time: 日 2022-06-05 00:40:36
Time zone: Asia/Beijing (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
[root@ls236 ~]# timedatectl set-ntp no
[root@ls236 ~]# timedatectl set-time "2020-06-05 17:01:37"
[root@ls236 ~]# timedatectl set-ntp yes
[root@ls236 ~]# timedatectl
Local time: 五 2020-06-05 17:01:45 CST
Universal time: 五 2020-06-05 09:01:45 UTC
RTC time: 五 2020-06-05 17:01:46
Time zone: Asia/Beijing (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
[root@ls236 ~]#
UTC+8 =北京时间
一、基本概念
1.1 GMT、UTC、CST、DST 时间
(1) UTC
整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。
(2) GMT
格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的×××格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)
(3) CST
中国标准时间 (China Standard Time)
|
1 |
GMT + 8 = UTC + 8 = CST |
(4) DST
夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时钟拨快一小时,以提早日光的使用。(中国不使用)
1.2 硬件时钟和系统时钟
(1) 硬件时钟
RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会继续运行。仅保存日期时间数值,无法保存时区和夏令时设置。
(2) 系统时钟
一般在服务器启动时复制RTC时间,之后独立运行,保存了时间、时区和夏令时设置。
二、timedatectl 命令
2.1 读取时间
|
1 |
timedatectl //等同于 timedatectl status |
2.2 设置时间
|
1 |
timedatectl set-time "YYYY-MM-DD HH:MM:SS" |
2.3 列出所有时区
|
1 |
timedatectl list-timezones |
2.4 设置时区
|
1 |
timedatectl set-timezone Asia/Shanghai |
2.5 是否NTP服务器同步
|
1 |
timedatectl set-ntp yes //yes或者no |
2.6 将硬件时钟调整为与本地时钟一致
|
1 2 |
timedatectl set-local-rtc 1 hwclock --systohc --localtime //与上面命令效果一致 |
注意 硬件时钟默认使用UTC时间,因为硬件时钟不能保存时区和夏令时调整,修改后就无法从硬件时钟中读取出准确标准时间,因此不建议修改。修改后系统会出现警告。
2.6 硬件时间设置成 UTC:
|
1 2 |
timedatectl set-local-rtc 1 hwclock --systohc --utc //与上面命令效果一致 |
三、设置系统时间为中国时区并启用NTP同步
|
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 即可.
====================================================================
解决Failed to set time: Automatic time synchronization is enabled错误
关闭同步
timedatectl set-ntp no
[root@ match]# timedatectl set-time 2018-11-13
date
Tue Nov 13 00:00:26 UTC 2018
开启同步
timedatectl set-ntp yes
CentOS 7 设置日期和时间 timedatectl的更多相关文章
- CentOS 7 设置日期和时间
现代操作系统分为以下两种类型的时钟: 实时时钟(Real-Time Clock,RTC),通常称为硬件时钟(一般是系统主板上的集成电路),它完全独立于操作系统的当前状态,即使在计算机关闭时也能运行. ...
- CentOS 7: 设置时区和时间
查看当前时区和时间 $ date $ ls -l /etc/localtime 查看所有可用时区 $ timedatectl list-timezones | grep Asia 设置时区 $ tim ...
- Centos 7 修改日期和时间的命令
timedatectl set-ntp no //关闭时间动态更新timedatectl set-time "YYYY-MM-DD HH:MM:SS" //设置时间和日期timed ...
- CentOS 7 设置时区、日期和时间
CentOS 7 设置时区.日期和时间 changhr2013关注 2019.04.19 01:33:09字数 307阅读 139 在 CentOS 7 中,引入了一个叫 timedatectl 的设 ...
- Centos date 设置自定义时间
[1]手动修改 (1)设置日期 # date -s 20190315 (2)设置时间 # date -s 15:23:34 (3)设置日期和时间 # date -s "20190315 15 ...
- Centos 7设置静态IP,修改时区,关闭防火墙
Centos 7设置静态IP # vi /etc/sysconfig/network-scripts/ifcfg-enxxx BOOTPROTO="static" ...... I ...
- 【转】Pro Android学习笔记(十七):用户界面和控制(5):日期和时间控件
目录(?)[-] DatePicker和TimePicker控件 DigitalClock和AnalogClock控件 DatePicker和TimePicker控件 使用DatePicker和Tim ...
- matlab中datest() 将日期和时间转换为字符串格式
来源:https://ww2.mathworks.cn/help/matlab/ref/datestr.html?searchHighlight=datestr&s_tid=doc_srcht ...
- CentOS下date命令 - 显示和设置系统日期与时间
显示系统日期 要显示系统日期,只要输入: $ date Thu Dec 5 22:55:41 WIB 2013 格式化显示日期 日期有很多格式.如果你不喜欢默认的格式,你可以换一种格式.你可能会想&q ...
随机推荐
- 批量实现SSH无密码登陆认证脚本
批量实现SSH无密码登陆认证脚本 问题背景 使用为了让linux之间使用ssh不需要密码,可以采用了数字签名RSA或者DSA来完成.主要使用ssh-key-gen实现. 1.通过 ssh-key-ge ...
- A. 1.划分数列
A . 1. 划 分 数 列 A. 1.划分数列 A.1.划分数列 氵水沝淼㵘解析 先预处理,然后公式推(详见代码) Code #include <bits/stdc++.h> using ...
- vue-router 监控全局路由,在路由中改变vuex中的状态值
- Unlink学习总结
Unlink 本文参考了CTF-wiki 和glibc 源码 原理: 我们在利用 unlink 所造成的漏洞时,其实就是借助 unlink 操作来达成修改指针的效果. 我们先来简单回顾一下 unlin ...
- Java中的绑定
1 前言 做了一次笔试题,发现了一题问答题,是关于Java绑定的: 当时做的时候是完全不会的... 于是这里补上一篇Java绑定的文章. 2 绑定 首先来了解一下绑定的概念.绑定是指一个方法的调用与方 ...
- Github Pages+Gridea搭建个人博客
1 概述 Github Pages可以用来托管个人网站,静态的,便于用来实现博客,可以在一个仓库的settings中开启: Gridea是一个静态博客写作客户端,所有文件都在本地,没有数据库,实现简单 ...
- 单个java文件打成可执行jar包
1 概述 使用JDK自带的jar与java将单个java文件打成可执行jar包并运行. 当然也可以使用IDE完成,使用Maven只需要一个简单的package,但是单个文件嘛,没必要这么"凶 ...
- 大话数据结构.epub
电子书资源:大话数据结构 书籍简介 本书为超级畅销书<大话设计模式>作者程杰潜心三年推出的扛鼎之作!通篇以一种趣味方式来叙述,大量引用了各种各样的生活知识来类比,并充分运用图形语言来体 ...
- AdaBoostClassifier参数
[AdaBoostClassifier] Adaboost-参数: base_estimator:基分类器,默认是决策树,在该分类器基础上进行boosting,理论上可以是任意一个分类器,但是如果是其 ...
- 移动端小总结(1)---meta、input和单行多行文字溢出省略号
一.常用META 1. 添加到主屏后的标题(IOS) 1 <meta name="apple-mobile-web-app-title" content="标题&q ...