1 How to view time in Linux

  • date

    1
    2
    $ date
    2021年 06月 25日 星期五 01:44:00 PDT
  • timedatectl

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    $ timedatectl
    Local time: 五 2021-06-25 01:44:34 PDT
    Universal time: 五 2021-06-25 08:44:34 UTC
    RTC time: 五 2021-06-25 08:44:34
    Time zone: America/Los_Angeles (PDT, -0700)
    NTP enabled: yes
    NTP synchronized: yes
    RTC in local TZ: no
    DST active: yes
    Last DST change: DST began at
    日 2021-03-14 01:59:59 PST
    日 2021-03-14 03:00:00 PDT
    Next DST change: DST ends (the clock jumps one hour backwards) at
    日 2021-11-07 01:59:59 PDT
    日 2021-11-07 01:00:00 PST

2 How to change timezone in Linux

But the timezone is not correct, so I need change the timezone in Linux.

First, you should know there is how many zone in Linux.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ 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
...

And you choose a timezone to set in your Linux with the following command:

1
2
3
$ sudo timedatectl set-timezone <your timezone name>
# for example
$ sudo timedatectl set-timezone Asia/Shanghai

Reference Page

How to Set or Change the Time Zone in Linux

写在最后

欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。
微信公众号