0
点赞
收藏
分享

微信扫一扫

linux系统的时间配置(date,clock,timedatectl,cal)

毅会 2024-10-30 阅读 13
Linux运维

date(显示软件时钟)

显示当前时间
[root@sre01 ~]# date
Fri Oct 18 16:31:57 CST 2024

显示时区
[root@sre01 ~]# date -R
Fri, 18 Oct 2024 16:31:59 +0800

显示当前时间的时间戳
[root@sre01 ~]# date +%s
1729240329

显示指定时间的时间戳
[root@sre01 ~]# date -d "1990-09-09" +%s
652806000


将时间戳转换为可读的时间
[root@sre01 ~]# date -d @11111111
Sat May  9 22:25:11 CST 1970

按指定格式显示时间
[root@sre01 ~]# date +%F
2024-10-18
[root@sre01 ~]# date +%T
16:34:48
[root@sre01 ~]# date +"%F %T"
2024-10-18 16:35:03

修改时间-s
[root@sre01 ~]# date
Fri Oct 18 16:48:32 CST 2024

[root@sre01 ~]# date -s 23:00
Fri Oct 18 23:00:00 CST 2024

[root@sre01 ~]# date 
Fri Oct 18 23:00:03 CST 2024

[root@sre01 ~]# date -s "2024-09-09 22:00"
Mon Sep  9 22:00:00 CST 2024

[root@sre01 ~]# date
Mon Sep  9 22:00:01 CST 2024

clock(显示硬件时钟)

  • -s (使用硬件时钟时间,覆盖系统时钟)
  • -w(使用系统时钟时间,覆盖硬件时钟)

[root@sre01 ~]# clock
Fri 18 Oct 2024 04:42:22 PM CST  -0.099331 seconds

[root@sre01 ~]# clock -s

[root@sre01 ~]# clock -w

timedatectl (配置时区,查看时间同步)

查看时间和时区和同步状态
[root@sre01 ~]# timedatectl 
      Local time: Fri 2024-10-18 16:44:24 CST
  Universal time: Fri 2024-10-18 08:44:24 UTC
        RTC time: Fri 2024-10-18 08:44:24
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

查看时间和时区和同步状态
[root@sre01 ~]# timedatectl  status
      Local time: Fri 2024-10-18 16:44:27 CST
  Universal time: Fri 2024-10-18 08:44:27 UTC
        RTC time: Fri 2024-10-18 08:44:27
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

设置时区
[root@sre01 ~]# timedatectl  set-timezone  Asia/Shanghai

查看所有支持的时区
[root@sre01 ~]# timedatectl list-timezones 
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar

cal (查看日历)

[root@sre01 ~]# cal
    October 2024    
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

[root@sre01 ~]# cal 1990
                               1990                               

       January               February                 March       
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6                1  2  3                1  2  3
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    4  5  6  7  8  9 10
14 15 16 17 18 19 20   11 12 13 14 15 16 17   11 12 13 14 15 16 17
21 22 23 24 25 26 27   18 19 20 21 22 23 24   18 19 20 21 22 23 24
28 29 30 31            25 26 27 28            25 26 27 28 29 30 31

        April                   May                   June        
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7          1  2  3  4  5                   1  2
 8  9 10 11 12 13 14    6  7  8  9 10 11 12    3  4  5  6  7  8  9
15 16 17 18 19 20 21   13 14 15 16 17 18 19   10 11 12 13 14 15 16
22 23 24 25 26 27 28   20 21 22 23 24 25 26   17 18 19 20 21 22 23
29 30                  27 28 29 30 31         24 25 26 27 28 29 30

        July                  August                September     
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7             1  2  3  4                      1
 8  9 10 11 12 13 14    5  6  7  8  9 10 11    2  3  4  5  6  7  8
15 16 17 18 19 20 21   12 13 14 15 16 17 18    9 10 11 12 13 14 15
22 23 24 25 26 27 28   19 20 21 22 23 24 25   16 17 18 19 20 21 22
29 30 31               26 27 28 29 30 31      23 24 25 26 27 28 29
                                              30
       October               November               December      
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6                1  2  3                      1
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    2  3  4  5  6  7  8
14 15 16 17 18 19 20   11 12 13 14 15 16 17    9 10 11 12 13 14 15
21 22 23 24 25 26 27   18 19 20 21 22 23 24   16 17 18 19 20 21 22
28 29 30 31            25 26 27 28 29 30      23 24 25 26 27 28 29
                                              30 31

[root@sre01 ~]# 

举报

相关推荐

0 条评论