修改Linux Operating System的时间与时区
修改Linux Operating System的时间与时区
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
有的小伙伴可能会遇到安装了linux系统后,尽管时区选择正确,也会发现系统时间不对。这是由于安装系统时采用了UTC,那么什么是UTC呢,简单的说UTC就是0时区的时间,是国际标准,而中国处于"UTC +800"时区。所以安装linux系统时,不要选择使用UTC。接下来我们就一起来学习一下如何将错误的时间修改为正确的时间。
一.修改Linux的本地时间
linux系统时钟有两个,一个是硬件时钟,即BIOS时间,就是我们进行CMOS设置时看到的时间,另一个是系统时钟,是linux系统Kernel时间。当Linux启动时,系统Kernel会去读取硬件时钟的设置,然后系统时钟就会独立于硬件运作。有时我们会发现系统时钟和硬件时钟不一致,因此需要执行时间同步,下面就分享一下时间设置及时钟同步的命令使用方法。
1>.查看系统时间
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# date
Tue Mar :: CST
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# date -s "2018-10-10 11:11:11" #修改系统时间
Wed Oct :: CST
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# date
Wed Oct :: CST
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
2>.查看系统硬件时钟
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock
Tue Mar :: PM CST -0.393951 seconds
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock --show
Tue Mar :: PM CST -0.954759 seconds
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# clock --show
Tue Mar :: PM CST -0.470718 seconds
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# type -a hwclock
hwclock is /usr/sbin/hwclock
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /usr/sbin/hwclock
-rwxr-xr-x. root root Oct : /usr/sbin/hwclock
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# type -a clock
clock is /usr/sbin/clock
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /usr/sbin/clock
lrwxrwxrwx. root root Mar : /usr/sbin/clock -> hwclock
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
clock与hwclock相同,其实clock底层调用的就是hwclock,详情请戳我!
3>.将系统时间同步到硬件时间中
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /etc/redhat-release
CentOS Linux release 7.6. (Core)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock -r
Tue Mar :: PM CST -0.158685 seconds
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock --set --date="06/18/18 13:55"
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock -r
Tue Mar :: PM CST -0.752022 seconds
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock --set --date="06/18/18 13:55" #cento7.6 设置硬件时间无效案例!
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /etc/redhat-release
CentOS Linux release 7.6. (Core)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# date
Tue Mar :: CST
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# date -s "2018-10-10 11:11:11"
Wed Oct :: CST
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# date
Wed Oct :: CST
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock -r
Tue Mar :: PM CST -0.674275 seconds
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock -w #centos7. 将系统时间同步到硬件时间无效案例!
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock -r
Tue Mar :: PM CST -0.830223 seconds
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hwclock -w #centos7.6 将系统时间同步到硬件时间无效案例!
二.通过配置文件的方式修改Linux时区
1>.查看Linux当前时区(温馨提示:负号(“-”) 代表西 , 正号(“+”) 代表东, 北京时间是东八区)
[root@yinzhengjie oozie-4.0.-cdh5.3.6]# date -R
Fri, Sep :: -
[root@yinzhengjie oozie-4.0.-cdh5.3.6]#
2>.查看时区的配置文件所在位置
[root@yinzhengjie oozie-4.0.-cdh5.3.6]# cd /usr/share/zoneinfo/
[root@yinzhengjie zoneinfo]# ll
total
drwxr-xr-x. root root Aug : Africa
drwxr-xr-x. root root Aug : America
drwxr-xr-x. root root Aug : Antarctica
drwxr-xr-x. root root Aug : Arctic
drwxr-xr-x. root root Aug : Asia
drwxr-xr-x. root root Aug : Atlantic
drwxr-xr-x. root root Aug : Australia
drwxr-xr-x. root root Aug : Brazil
drwxr-xr-x. root root Aug : Canada
-rw-r--r--. root root Oct CET
drwxr-xr-x. root root Aug : Chile
-rw-r--r--. root root Oct CST6CDT
-rw-r--r--. root root Oct Cuba
-rw-r--r--. root root Oct EET
-rw-r--r--. root root Oct Egypt
-rw-r--r--. root root Oct Eire
-rw-r--r--. root root Oct EST
-rw-r--r--. root root Oct EST5EDT
drwxr-xr-x. root root Aug : Etc
drwxr-xr-x. root root Aug : Europe
-rw-r--r--. root root Oct GB
-rw-r--r--. root root Oct GB-Eire
-rw-r--r--. root root Oct GMT
-rw-r--r--. root root Oct GMT0
-rw-r--r--. root root Oct GMT-
-rw-r--r--. root root Oct GMT+
-rw-r--r--. root root Oct Greenwich
-rw-r--r--. root root Oct Hongkong
-rw-r--r--. root root Oct HST
-rw-r--r--. root root Oct Iceland
drwxr-xr-x. root root Aug : Indian
-rw-r--r--. root root Oct Iran
-rw-r--r--. root root May iso3166.tab
-rw-r--r--. root root Oct Israel
-rw-r--r--. root root Oct Jamaica
-rw-r--r--. root root Oct Japan
-rw-r--r--. root root Oct Kwajalein
-rw-r--r--. root root Oct Libya
-rw-r--r--. root root Oct MET
drwxr-xr-x. root root Aug : Mexico
-rw-r--r--. root root Oct MST
-rw-r--r--. root root Oct MST7MDT
-rw-r--r--. root root Oct Navajo
-rw-r--r--. root root Oct NZ
-rw-r--r--. root root Oct NZ-CHAT
drwxr-xr-x. root root Aug : Pacific
-rw-r--r--. root root Oct Poland
-rw-r--r--. root root Oct Portugal
drwxr-xr-x. root root Aug : posix
-rw-r--r--. root root Oct posixrules
-rw-r--r--. root root Oct PRC
-rw-r--r--. root root Oct PST8PDT
drwxr-xr-x. root root Aug : right
-rw-r--r--. root root Oct ROC
-rw-r--r--. root root Oct ROK
-rw-r--r--. root root Oct Singapore
-rw-r--r--. root root Oct Turkey
-rw-r--r--. root root Oct UCT
-rw-r--r--. root root Oct Universal
drwxr-xr-x. root root Aug : US
-rw-r--r--. root root Oct UTC
-rw-r--r--. root root Oct WET
-rw-r--r--. root root Oct W-SU
-rw-r--r--. root root Sep zone.tab
-rw-r--r--. root root Oct Zulu
[root@yinzhengjie zoneinfo]#
3>.删除本地配置文件
[root@yinzhengjie zoneinfo]# rm -rf /etc/localtime
[root@yinzhengjie zoneinfo]#
4>.创建一个软连接
[root@yinzhengjie zoneinfo]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@yinzhengjie zoneinfo]#
5>.再次查看Linux当前时区(时区变成东八区了)
[root@yinzhengjie zoneinfo]# date -R
Fri, Sep :: +
[root@yinzhengjie zoneinfo]#
三.通过Linux命令的方式修改Linux时区
[root@node101 ~]# date -R #我们通过该命令查看到当前到时区不正确!
Thu, Feb :: -
[root@node101 ~]#
[root@node101 ~]# timedatectl #当然,我们可以同这条命令查看比上面到命令现实到信息更加详细。
Local time: Thu -- :: EST
Universal time: Thu -- :: UTC
RTC time: Thu -- ::
Time zone: America/New_York (EST, -)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun -- :: EDT
Sun -- :: EST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun -- :: EST
Sun -- :: EDT
[root@node101 ~]#
[root@node101 ~]#
[root@node101 ~]# timedatectl list-timezones | grep -E "Asia/S.*" #查看关于亚洲到区域。
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
[root@node101 ~]#
[root@node101 ~]# timedatectl set-timezone Asia/Shanghai #我们设置当前到时区为亚洲上海时间
[root@node101 ~]#
[root@node101 ~]# timedatectl #再次查看日期,发现是亚洲时间了
Local time: Thu -- :: CST
Universal time: Thu -- :: UTC
RTC time: Thu -- ::
Time zone: Asia/Shanghai (CST, +)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@node101 ~]#
[root@node101 ~]# date -R #恭喜你,修改时区成功啦~
Thu, Feb :: +
[root@node101 ~]#
修改Linux Operating System的时间与时区的更多相关文章
- Linux中设置系统时间和时区
之前公司里有需求要做机器与服务器做时间同步,服务器发送时间戳和时区过来,机器这边根据接收到的时间戳和时区来改时间. 其实很简单,百度上应该也有很多博客有类似的教程,但是这里强调一点,百度上的博客里写的 ...
- Linux操作系统以及各大发行版介绍——Linux operating system and major distribution is introduced
什么是Linux? 也许很多人会不屑的说,Linux不就是个操作系统么.错!Linux不是一个操作系统,严格来讲,Linux只是一个操作系统中的内核.内核是什么?内核建立了计算机软件与硬件之间通讯的平 ...
- Linux operating system basic knowleadge
1.Linux目录系统结构 It makes sense to explore the Linux filesystem from a terminal window. In fact, that ...
- 修改Linux系统日期与时间date clock
先设置日期 date -s 20080103 再设置时间 date -s 18:24:30 为了永久生效,需要将修改的时间写入CMOS. 查看CMOS的时间: #clock -r 将当前系统时间写到C ...
- 查看修改Linux时区和时间
查看/修改Linux时区和时间 一.时区 1. 查看当前时区 date -R 2. 修改设置时区 方法(1) tzselect 方法(2) 仅限于RedHat Linux 和 CentOS timec ...
- 查看/修改 Linux 时间和时区
查看/修改Linux时区和时间 一.时区 1. 查看当前时区 date -R 2. 修改设置时区 方法(1) ...
- 查看和修改Linux服务器的时区和时间
一.查看和修改Linux的时区1. 查看当前时区 命令 : "date -R" 2. 修改设置Linux服务器时区方法 A 命令 : "tzselect" 方法 ...
- linux下修改时间和时区
一.修改linux的时间在root用户下,使用date指令:date -s1.只修改日期,不修改时间,输入: date -s -- 2.只修改时间,输入: date -s :: 3.同时修改日期时间, ...
- Linux查看修改时间、时区
同步网络时间 yum install ntpntpdate time.nist.gov timedatectl set-timezone Asia/Shanghai如果上面time.nist.gov服 ...
随机推荐
- 七牛云域名DV SSL证书申请流程以及CDN融合加速配置
从2017年起,苹果ios以及微信小程序都陆续要求请求连接request地址是使用HTTPS协议的.所以在项目开发阶段就要考虑解决https的问题,同时这也是为项目实际安全所考虑.最近我也是在折腾项目 ...
- Maven的课堂笔记2
5 maven的核心概念 5.1 项目对象模型 说明: maven根据pom.xml文件,把它转化成项目对象模型(POM),这个时候要解析依赖关系,然后去相对应的maven库中查找到依赖的jar包. ...
- Use curl with uuid(uuidgen) under shell
#!set uuidtmp = uuid.tmp #!uuidgen > $uuidtmp #!set uuid=<$uuidtmp #!rm $uuidtmp #!echo $uuid ...
- Chrome 启动参数列表
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --type=gpu-process --channel ...
- [转帖]总结ORACLE系统视图及表大全
总结ORACLE系统视图及表大全:dba_开头.....dba_users 数据库用户信息dba_segments 表段信息dba_extents 数据区信息dba_objects 数据库对象信息db ...
- 【工具技巧】:sublime notepad++ 多行编辑
1. 多行编辑 sublime 最简单的多行编辑实现方法 1. 鼠标选中文件 然后按 ctrl+D 自动选中相同的进行同时编辑 2.选中shift按键+鼠标右键进行选择,可以同时选中多行进行编辑. n ...
- 数组 this.setData快捷赋值
let list=this.data.list; let listString = `{"list[${index}].sliderSure":${!list[index].sli ...
- Linux基础学习(5)--文本编辑器Vim
第五章——文本编辑器Vim 一. Vim常用操作 1.Vim简介: Vim是一个功能强大的全屏幕文本编辑器,是Linux/UNIX上最常用的文本编辑器,它的作用是建立.编辑. ...
- Maven Archetype简介以及搭建
为什么会写这篇文章,因为公司先在构建项目骨架都是用的 maven archetype ,身为一个上进的渣渣猿,自己还是有必要了解下这个东西的. Archetype介绍 Archetype 是一个 Ma ...
- rgb & rgba convert
rgb & rgba convert RGB color to Hex, Pantone, RAL, HSL, HSV, HSB, JSON. Get color scheme. https: ...