修改

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

timedatectl set-ntp no

timedatectl

timedatectl set-time 2022-06-04

timedatectl

2018.05.11 00:17:49字数 740阅读 1,069

在过去的CentOS版本里,要设置时区的话要手动修改 /etc/locale .conf文件,很是麻烦,不过CentOS 7 已经为我们准备好一个非常强大的工具了: localectl

显示当前时区

使用以下命令:

复制代码

代码如下:

~]$ localectl status

System Locale: LANG=en_US.UTF-8

VC Keymap: us

X11 Layout: n/a

可以看到,除了显示了系统的时区信息以外,还显示了键盘信息和X11布局信息

列出所有的时区

用以下命令显示所有的英文时区

复制代码

代码如下:

~]$ localectl list-locales | grep en_

en_AG

en_AG.utf8

en_AU

en_AU.iso88591

en_AU.utf8

en_BW

en_BW.iso88591

en_BW.utf8

如果要显示中文的,只需要把grep en 改成grep zh就行了

设置本地时区

使用Root执行以下命令:

复制代码

代码如下:

localectl set-locale LANG=locale

把最后的 locale 替换成具体的时区,比如zh_CN.UTF-8就可以设置了。

是不是很强大啊。

timedatectl

下面隆重来介绍一下timedatectl命令~

在以前的CentOS版本里,时间设置有 date , hwclock 等一系列命令,但是CentOS 7 开始,使用了一个统一的命令:

复制代码

代码如下:

timedatectl

这个命令非常的强大,首先是直接使用可以显示当前的系统时间的一些信息:

复制代码

代码如下:

~]$ timedatectl

Local time: Mon 2013-09-16 19:30:24 CEST

Universal time: Mon 2013-09-16 17:30:24 UTC

Timezone: Europe/Prague (CEST, +0200)

NTP enabled: no

NTP synchronized: no

RTC in local TZ: no

DST active: yes

Last DST change: DST began at

Sun 2013-03-31 01:59:59 CET

Sun 2013-03-31 03:00:00 CEST

Next DST change: DST ends (the clock jumps one hour backwards) at

Sun 2013-10-27 02:59:59 CEST

Sun 2013-10-27 02:00:00 CET

设置当前日期:

使用Root执行以下命令就可以了:

复制代码

代码如下:

timedatectl set-time YYYY-MM-DD

设置当前时间:

依旧是要Root权限

复制代码

代码如下:

timedatectl set-time HH:MM:SS

默认的,系统是使用UTC时间的,可以用以下命令打开和关闭UTC时间:

复制代码

代码如下:

timedatectl set-local-rtc boolean

把 boolean 替换成yes则表示使用本地时间,替换成no则表示是UTC时间

设置任意时区

可以用以下命令查看所有的时区:

复制代码

代码如下:

timedatectl list-timezones

然后用以下命令设置时区:

复制代码

代码如下:

timedatectl set-timezone time_zone

当然root权限是免不了的

与远程NTP服务器同步

timedatectl还可以设置是否打开NTP选项

复制代码

代码如下:

timedatectl set-ntp boolean

同样的,这里的boolean是yes或者no

 
 

1人点赞

 
linux

 

# timedatectl status
Local time: 三 2020-06-03 16:16:54 CST
Universal time: 三 2020-06-03 08:16:54 UTC
RTC time: 三 2020-06-03 08:16:54
Time zone: Asia/Beijing (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@ls236 ~]# timedatectl
Local time: 三 2020-06-03 16:17:12 CST
Universal time: 三 2020-06-03 08:17:12 UTC
RTC time: 三 2020-06-03 08:17:12
Time zone: Asia/Beijing (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@ls236 ~]# timedatectl set-local-rtc boolean
Failed to parse local RTC setting: boolean
[root@ls236 ~]#
[root@ls236 ~]# timedatectl set-local-rtc yes
[root@ls236 ~]# timedatectl set-time 2022-06-04
Failed to set time: Automatic time synchronization is enabled
[root@ls236 ~]# timedatectl --help
timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

-h --help Show this help message
--version Show package version
--no-pager Do not pipe output into a pager
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--adjust-system-clock Adjust system clock when changing local RTC mode

Commands:
status Show current time settings
set-time TIME Set system time
set-timezone ZONE Set system time zone
list-timezones Show known time zones
set-local-rtc BOOL Control whether RTC is in local time
set-ntp BOOL Control whether NTP is enabled
[root@ls236 ~]# timedatectl set-ntp
Invalid number of arguments.
[root@ls236 ~]# timedatectl set-ntp --help
timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

-h --help Show this help message
--version Show package version
--no-pager Do not pipe output into a pager
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--adjust-system-clock Adjust system clock when changing local RTC mode

Commands:
status Show current time settings
set-time TIME Set system time
set-timezone ZONE Set system time zone
list-timezones Show known time zones
set-local-rtc BOOL Control whether RTC is in local time
set-ntp BOOL Control whether NTP is enabled
[root@ls236 ~]# timedatectl set-ntp BOOL
Failed to parse NTP setting: BOOL
[root@ls236 ~]# timedatectl set-ntp YES
[root@ls236 ~]# timedatectl
Local time: 三 2020-06-03 16:19:05 CST
Universal time: 三 2020-06-03 08:19:05 UTC
RTC time: 三 2020-06-03 16:19:05
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 ~]# timedatectl set-ntp NO
[root@ls236 ~]# timedatectl
Local time: 三 2020-06-03 16:19:13 CST
Universal time: 三 2020-06-03 08:19:13 UTC
RTC time: 三 2020-06-03 16:19:13
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-time 2022-06-04
[root@ls236 ~]# date
2022年 06月 04日 星期六 00:00:01 CST
[root@ls236 ~]#

 

CentOS 7系统中的时间日期设置的更多相关文章

  1. CentOS linux系统将UTC时间修改为CST时间

    1.编辑时间配置文件 1 2 3 4 # vi /etc/sysconfig/clock           ZONE="Asia/Shanghai"     UTC=false  ...

  2. linux系统中的时间

    1.编程显示系统时间: #include <stdio.h> #include <time.h> /* gcc -o fix fixedFormatTime.c ./fix * ...

  3. 在centos 64bit 系统中安装使用WPS office的方法

    1. 安装32位开发库: yum install xulrunner.i686 yum install libXtst.i686 2. 在官网下载 wps-office-8.1.0.3724-0.1. ...

  4. 浅析 Linux 中的时间编程和实现原理一—— Linux 应用层的时间编程【转】

    本文转载自:http://www.cnblogs.com/qingchen1984/p/7007631.html 本篇文章主要介绍了"浅析 Linux 中的时间编程和实现原理一—— Linu ...

  5. Spire.Cloud 私有化部署教程(一) - CentOS 7 系统

    Spire.Cloud支持的Linux服务器系统包括CentOS和Ubuntu(推荐使用CentOS 7和Ubuntu 18版本),本教程主要介绍如何在CentOS 7系统上实现Spire.Cloud ...

  6. ubantu/centos修改系统时间

    前言:有时系统上的时间和真实的时间对应不是,或者有特殊需求,需要修改系统时间.但是对应多台的服务器系统更改时间,手动的话很麻烦,这就需要写脚本或者搭建时间服务器了,统一时间,以下是对于一个不同系统修改 ...

  7. CentOS 7 时间, 日期设置 (含时间同步)

    from http://blog.itnmg.net/centos-7-time-date/ yum install ntp //安装ntp服务systemctl enable ntpd //开机启动 ...

  8. CentOS 6.4系统中编译和升级内核

    CentOS 6.4系统中编译和升级内核 [日期:2013-08-25] 来源:Linux社区  作者:vipshichg [字体:大 中 小] 可能因为以下几种原因,你可能需要对Linux kern ...

  9. CentOS 6.x 系统中安装原生 Hadoop 2

    2020年整理博客发现原文地址已经失效,推荐学习地址厦门大学数据库实验室 本教程适合于在 CentOS 6.x 系统中安装原生 Hadoop 2,适用于Hadoop 2.7.1, Hadoop 2.6 ...

随机推荐

  1. 使用 Elastic 技术栈构建 Kubernetes全栈监控

    以下我们描述如何使用 Elastic 技术栈来为 Kubernetes 构建监控环境.可观测性的目标是为生产环境提供运维工具来检测服务不可用的情况(比如服务宕机.错误或者响应变慢等),并且保留一些可以 ...

  2. 99%的Python用户都不知道的f-string隐秘技巧

    f-string想必很多Python用户都基础性的使用过,作为Python3.6版本开始引入的特性,通过它我们可以更加方便地向字符串中嵌入自定义内容,但f-string真正蕴含的功能远比大多数用户知道 ...

  3. Hadoop学习笔记—Yarn

    目录 一些基本知识 ResourceManager 的恢复 Resource Manager的HA YARN Node Labels YARN Node Attributes Web Applicat ...

  4. React 错误边界组件

    这是React16的内容,并不是最新的技术,但是用很少被讨论,直到通过文档发现其实也是很有用的一部分内容,还是总结一下- React中的未捕获的 JS 错误会导致整个应用的崩溃,和整个组件树的卸载.从 ...

  5. arthas使用

    博客原地址:https://blog.csdn.net/u013076044/article/details/83626202 arthas使用 文章目录 准备 启动Demo 进入arthas控制台 ...

  6. java面试-synchronized与lock有什么区别?

    1.原始构成: synchronized是关键字,属于JVM层面,底层是由一对monitorenter和monitorexit指令实现的. ReentrantLock是一个具体类,是API层面的锁. ...

  7. Linux下Matlab的安装

    1 概述 笔者环境Manjaro,本来想直接通过yay安装的,但无奈失败了,于是直接从官网下载进行安装. 2 下载安装包 Matlab官网可以戳这里,点击右上角的Get MATLAB就可以下载了: 没 ...

  8. Day05_25_Super关键字

    Super关键字 Super关键字的所用 Super关键字的用法有三种: 在子类的成员方法中,访问父类的成员变量. 在子类的成员方法中,访问父类的成员方法. 在子类的构造方法中,访问父类的构造方法. ...

  9. 473. Matchsticks to Square

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  10. 【死磕ibatis】SqlMapClient 基本操作示例

    前言:想要学习ibatis,我这里写了一些关于SqlMapClient 的具体例子,希望对你有帮助.话不多说,直接看例子. 例 1: 数据写入操作(insert, update, delete): s ...