修改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服 ...
随机推荐
- <<梦断代码>>阅读笔记三
看完了这最后三分之一的<梦断代码>,意味着这本软件行业的著作已经被我粗略地过了一遍. 在这最后三分之一的内容中,我深入了解了在大型软件项目的运作过程中存在的困难和艰辛.一个大型软件项目的成 ...
- android——error opening trace file: No such file or directory (2)
1.疑惑: 程序运行起来的时候日志总是显示下面这个错误,但是不影响程序的正常进行,我是用真机来测试的,android4.4.4(API17). 02-11 14:55:03.629 15525-155 ...
- 【软件工程Ⅱ】作业二 |分布式版本控制系统Git的安装与使用
本次作业的要去来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 远程库地址:https://github.com/Mol ...
- Alpha冲刺随笔汇总
项目Alpha冲刺(团队) Alpha冲刺随笔汇总 姓名 学号 博客链接 何守成 031602408 http://www.cnblogs.com/heshoucheng/ 黄锦峰 031602411 ...
- php 文件上传 $_FILES 错误码
假设文件上传字段的名称file_name,则: $_FILES['file_name']['error']有以下几种类型 1.UPLOAD_ERR_OK 其值为 0,没有错误发生,文件上传成功. 2. ...
- [转帖]召冠总的 Oracle常用的性能诊断语句. --保存学习备查
Copyfrom https://www.cnblogs.com/zhaoguan_wang --1.阻塞及等待事件信息查询-- 查询所有会话的状态.等待类型及当前正在执行的SQL脚本select t ...
- Node 开启
cmd //进入命令行 D: //指定磁盘 cd 文件路径 //指定路径 node 文件名.js //执行文件 增补: Node执行js文件自动嵌套 (functio ...
- 如何实现圆形的进度条(ProgressBar)
在我们实际的工作中可能经常使用到圆形的进度条,但是这是怎么实现的呢?其实这只不过是修改了一下ProgressBar的模板,我们在下面的代码中我们将ProgressBar的Value值绑定到Border ...
- SQL ROUND函数的使用
SQL ROUND函数的使用 SQL ROUND函数是对数据进行制定精度的取值. 第一个参数是取值的数据,第二个参数是精度,第三个参数是数据取值模式(四舍五入还是截断),其中第三个参数是可选参数, ...
- Python——socketsever模块
1.作用:同时与多个客户端通信 import socketserver class MyServer(skcketserver.BaseRequestHandler): def handle(self ...