Linux 有两种时钟

  1. 系统时钟
  2. 硬件时钟

查看系统时钟

  • date
[Tue Mar 23 03:15:00 root@C8-1 ~]#date
Tue Mar 23 03:19:38 EDT 2021
Tue Mar 23 15:18 u20@u20-52:~$date
Tue 23 Mar 2021 03:19:32 PM CST

查看硬件时钟

Ubuntu

  • sudo hwclock --show
Tue Mar 23 15:24 u20@u20-52:~$sudo hwclock --show
2021-03-23 15:25:13.103163+08:00

CentOS

  • hwclock --show
  • clock
[Tue Mar 23 03:19:38 root@C8-1 ~]#hwclock --show
2021-03-23 03:27:25.447303-04:00
[Tue Mar 23 03:27:25 root@C8-1 ~]#clock
2021-03-23 03:27:34.119573-04:00

clock是hwclock的软链接

[Tue Mar 23 04:40:41 root@C8-1 ~]#ll `which clock`
lrwxrwxrwx. 1 root root 7 Nov  8  2019 /usr/sbin/clock -> hwclock

查看日历

Tue Mar 23 15:25 u20@u20-52:~$cal -y
                            2021
      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      1  2  3  4  5  6      1  2  3  4  5  6
 3  4  5  6  7  8  9   7  8  9 10 11 12 13   7  8  9 10 11 12 13
10 11 12 13 14 15 16  14 15 16 17 18 19 20  14 15 16 17 18 19 20
17 18 19 20 21 22 23  21 22 23 24 25 26 27  21 22 23 24 25 26 27
24 25 26 27 28 29 30  28                    28 29 30 31
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                     1         1  2  3  4  5
 4  5  6  7  8  9 10   2  3  4  5  6  7  8   6  7  8  9 10 11 12
11 12 13 14 15 16 17   9 10 11 12 13 14 15  13 14 15 16 17 18 19
18 19 20 21 22 23 24  16 17 18 19 20 21 22  20 21 22 23 24 25 26
25 26 27 28 29 30     23 24 25 26 27 28 29  27 28 29 30
                      30 31

        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   1  2  3  4  5  6  7            1  2  3  4
 4  5  6  7  8  9 10   8  9 10 11 12 13 14   5  6  7  8  9 10 11
11 12 13 14 15 16 17  15 16 17 18 19 20 21  12 13 14 15 16 17 18
18 19 20 21 22 23 24  22 23 24 25 26 27 28  19 20 21 22 23 24 25
25 26 27 28 29 30 31  29 30 31              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      1  2  3  4  5  6            1  2  3  4
 3  4  5  6  7  8  9   7  8  9 10 11 12 13   5  6  7  8  9 10 11
10 11 12 13 14 15 16  14 15 16 17 18 19 20  12 13 14 15 16 17 18
17 18 19 20 21 22 23  21 22 23 24 25 26 27  19 20 21 22 23 24 25
24 25 26 27 28 29 30  28 29 30              26 27 28 29 30 31
31

神奇的1752年

[Tue Mar 23 04:45:29 root@C8-1 ~]#cal 9 1752
   September 1752   
Su Mo Tu We Th Fr Sa
       1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

查看时区

Tue Mar 23 15:42 u20@u20-52:~$cat /etc/timezone
Asia/Shanghai

[Tue Mar 23 03:38:39 root@C8-1 ~]#timedatectl status
               Local time: Tue 2021-03-23 03:39:37 EDT
           Universal time: Tue 2021-03-23 07:39:37 UTC
                 RTC time: Tue 2021-03-23 07:39:38
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[Tue Mar 23 03:40:06 root@C8-1 ~]#timedatectl list-timezones | head -10
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre

设置时区

[03:49:29 root@C8-3-55 ~]#timedatectl --help
timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

  -h --help                Show this help message
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-ask-password     Do not prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
     --adjust-system-clock Adjust system clock when changing local RTC mode
     --monitor             Monitor status of systemd-timesyncd
  -p --property=NAME       Show only properties by this name
  -a --all                 Show all properties, including empty ones
     --value               When showing properties, only print the value

Commands:
  status                   Show current time settings
  show                     Show properties of systemd-timedated
  set-time TIME            Set system time
  set-timezone ZONE        Set system time zone
  list-timezones           Show known time zones
  set-local-rtc BOOL       Control whether RTC is in local time
  set-ntp BOOL             Enable or disable network time synchronization

systemd-timesyncd Commands:
  timesync-status          Show status of systemd-timesyncd
  show-timesync            Show properties of systemd-timesyncd
[03:51:41 root@C8-3-55 ~]#timedatectl set-timezone
Display all 426 possibilities? (y or n)
[03:51:41 root@C8-3-55 ~]#timedatectl set-timezone America/New_York
[03:52:45 root@C8-3-55 ~]#timedatectl status
               Local time: 二 2021-03-23 03:53:00 EDT
           Universal time: 二 2021-03-23 07:53:00 UTC
                 RTC time: 二 2021-03-23 07:53:00
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
Logo

更多推荐