修改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服 ...
随机推荐
- java中for循环的几种方式
比如定义一个数组int a[]={1, 2, 3, 4},下面我们罗列一下遍历这个数组的方法 1 for(;;) 这也是最常用的方法,不多做解释.代码如下 int a[] = {1, 2, 3, 4} ...
- ejabberd在windows10下的配置文件ejabberd.yml存放路径
cd %USERPROFILE%\AppData\Roaming\ejabberd\conf C:\Users\Administrator\AppData\Roaming\ejabberd\conf
- Delphi/XE2 使用TIdHttp控件下载Https协议服务器文件[转]
之前的一篇博文详细描述了使用TIdhttp控件下载http协议的文件,在我项目的使用过程中发现对于下载Https协议中的文件与Http协议的文件不同,毕竟Https在HTTP协议基础上增加了SSL协议 ...
- 数组操作方法(包括es5)
//push(); 定义:可以可向数组的末尾添加一个或更多元素,并返回新的长度. 方法:push(); 语法:数组.push(新元素1,新元素2,....,新元素x) 返回值:把指定的值添加到数组后的 ...
- flask客户端测试使用设置cookie参数
今天在对flask客户端进行测试,然后看到我们服务器端用请求前钩子写了这样的代码 @app.before_requestdef before_request(): session = request. ...
- Ideal test 不执行main方法了
参考:idea 导入项目后不能执行main方法 用了ideal之后,发现自己的项目里面没有test文件夹,自己建了一个,发现竟然不能执行main函数, 后来经过点播之后,才知道,光建立文件夹是没用的, ...
- 一步步分析为什么B+树适合作为索引的结构
在MySQL中,主要有四种类型的索引,分别为:B-Tree索引,Hash索引,Fulltext索引和R-Tree索引,本文讲的是B-Tree索引. 什么是索引 索引(Index)是帮助数据库高效获取数 ...
- Delphi 实现获取其他程序的子窗体
通过一个父窗体的句柄,递归的枚举它的子窗体,我们可以最终找到需要的子窗体. 用法如下: nParentHandle: HWnd; nChildHandle: HWnd; nParentHandle : ...
- codeforces431B
Shower Line CodeForces - 431B Many students live in a dormitory. A dormitory is a whole new world of ...
- git-stash用法小结
[时间:2016-10] [状态:Open] [关键词:git,版本控制,版本管理,stash,git储藏] 缘起 今天在看一个bug,之前一个分支的版本是正常的,在新的分支上上加了很多日志没找到原因 ...