timedatectl命令与tzselect命令

时间:2019-11-10 11:44:41   收藏:0   阅读:122

timedatectl命令
显示系统的当前时间和日期,使用timedatectl命令,可加选项status显示信息一样

[root@XX ~]# timedatectl
      Local time: Sun 2019-11-10 01:36:55 GMT
  Universal time: Sun 2019-11-10 01:36:55 UTC
        RTC time: Sun 2019-11-10 01:36:55
       Time zone:             (GMT, +0000)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2019-10-27 01:59:59 BST
                  Sun 2019-10-27 01:00:00 GMT
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2020-03-29 00:59:59 GMT
                  Sun 2020-03-29 02:00:00 BST
[root@XX ~]# timedatectl status
......

要查看所有可用的时区,运行以下命令:

[root@XX ~]#  timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
......

要在Linux中设置本地时区,使用set-timezone开关,如下所示。

[root@XX ~]#  timedatectl set-timezone "Europe/London"

推荐使用和设置协调世界时,即UTC。

 

设置Linux中的时间。只设置时间的话,我们可以使用set-time开关以及HH:MM:SS(小时,分,秒)的时间格式。

在Linux中设置日期。只设置日期的话,我们可以使用set-time开关以及YY:MM:DD(年,月,日)的日期格式。

[root@XX ~]# timedatectl set-time 00:00:00
[root@XX ~]# timedatectl set-time 2019-11-10

 

将Linux系统时钟同步到远程NTP服务器

[root@XX ~]# timedatectl set-ntp false  #  关闭同步
[root@XX ~]# timedatectl set-ntp true   #  开启同步

  NTP即Network Time Protocol(网络时间协议),是一个互联网协议,用于同步计算机之间的系统时钟。timedatectl实用程序可以自动同步你的Linux系统时钟到使用NTP的远程服务器。

  注意,你必须在系统上安装NTP以实现与NTP服务器的自动时间同步。

 

查看系统时间设置详细信息

 在CentOS中可以tzselect进行时区查询,但是tzselect不会修改时区需要在命令行中输入TZ=‘查询到的时区‘; export TZ,

[root@XX ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 8
Please select a country.
 1) Albania          18) Guernsey            35) Poland
 2) Andorra          19) Hungary            36) Portugal
 3) Austria          20) Ireland            37) Romania
 4) Belarus          21) Isle of Man        38) Russia
 5) Belgium          22) Italy            39) San Marino
 6) Bosnia & Herzegovina  23) Jersey            40) Serbia
 7) Britain (UK)      24) Latvia            41) Slovakia
 8) Bulgaria          25) Liechtenstein        42) Slovenia
 9) Croatia          26) Lithuania            43) Spain
10) Czech Republic      27) Luxembourg        44) Sweden
11) Denmark          28) Macedonia            45) Switzerland
12) Estonia          29) Malta            46) Turkey
13) Finland          30) Moldova            47) Ukraine
14) France          31) Monaco            48) Vatican City
15) Germany          32) Montenegro        49) Åland Islands
16) Gibraltar          33) Netherlands
17) Greece          34) Norway
#? 7

The following information has been given:

    Britain (UK)

Therefore TZ=Europe/London will be used.
Local time is now:    Sun Nov 10 02:57:55 GMT 2019.
Universal Time is now:    Sun Nov 10 02:57:55 UTC 2019.
Is the above information OK?
1) Yes
2) No
Please enter 1 for Yes, or 2 for No.
#? 1

You can make this change permanent for yourself by appending the line
    TZ=Europe/London; export TZ
to the file .profile in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Europe/London

在CentOS6中可以通过以下方法修改时区

修改linux系统时区
    1) 可修改/etc/sysconfig/clock 
        ZONE=Europe/London  #  可以用tzselect查询获得或者在/usr/share/zoneinfo下查找 

        UTC=false ( 硬件时钟是否为UTC或者说GMT时钟 ) 
        ARC=false (如果是在 Alpha 机器上,则设置为 true ) 
   
把硬件时钟设置为 UTC 的好处就是他能自动设置夏时制,缺点是,在安装有多重操作系统启动的机器上,在另外的操作系统上时钟会错误。 
    2)删除时区链接文件重新连接

        rm /etc/localtime 
     
   ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!