How to Configure Time Zone and System Clock in Linux

In this tutorial, we will look at how to change your time zone settings in Linux and how to use NTP to sync the Linux system clock to your time zone.

Check Time Zone Settings

Check the current time zone settings.

date

output:

Fri May 20 13:36:53 UTC 2022

As you can see, my system time zone is set to UTC (Universal Time Coordinated). But I live in China right now. So I need to change time zone settings from UTC to CST (China Standard Time).

Change Time Zone on Debian-based Linux Distros

On Debian-based Linux distros, including Debian, Ubuntu, Linux Mint, Elementary OS, etc, you can change your time zone settings with this command.

sudo dpkg-reconfigure tzdata

It will open up a dialog in the terminal to let your select your geographic area.

change time zone setting on Debian-based linux

Next, select the city or region corresponding to your time zone. I live in China, so I selected Shanghai.

select the city or region corresponding to your time zone.

After you hit the OK button, your system clock will be immediately changed to your time zone clock.

A Distro-Agnostic Way to Change Time Zone Settings

This method works on all Linux distributions. First, open a terminal and type this command:

sudo ln -sf /usr/share/zoneinfo/

Don’t press Enter yet, press Tab key instead.

change time zone settings

A list of geographic areas will appear, now enter the name of your area after sudo ln -sf /usr/share/zoneinfo/. For example, I entered Asia. Then press Tab key again.  A list of City will appear.

change time zone settings in terminal

Enter the name of the city corresponding to your time zone. For instance, I entered Shanghai. Now press the space key and enter /etc/localtime. So the final command will be

sudo ln -sf /usr/share/zoneinfo/your-geographic-area/your-city /etc/localtime

Press enter to run this command. It will create a symbolic link pointing /etc/localtime file to your specific time zone file. Your system’s clock will be updated immediately, as you can find out by entering date command in the terminal. But users with a desktop environment such as XFCE need to log out and log back in to see the changes on the taskbar.

Real-Time Clock

RTC stands for real-time clock, also known as hardware clock. This clock is powered by CMOS battery of your computer’s motherboard. This clock runs all the time even if you shutdown your computer. Sometimes RTC time is incorrect.

To find out RTC time on your computer, run this command:

timedatectl

Output:

               Local time: Fri 2022-05-20 21:42:26 +08
           Universal time: Fri 2022-05-20 13:42:26 UTC
                 RTC time: Fri 2022-05-20 13:42:26
                Time zone: Asia/Singapore (+08, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

As you can see, my local time is now 21:42:26, but RTC time is 13:42:26. RTC time is not in my local time zone and sometimes this can cause problems if the RTC time is inaccurate. RTC time is unreliable.

To make your system read RTC time in UTC standard, execute the following command.

timedatectl set-local-rtc 0

To let your system read RTC time in the local time zone, run this command

timedatectl set-local-rtc 1

It’s recommended your system read RTC time in UTC standard to prevent unexpected behavior.

Synchronize System Clock to Your Time Zone

Sometimes, your system clock can still be incorrect even if you set the correct time zone. To make sure your system clock is synchronized to your local time zone, you need NTP (Network Time Protocol).

NTP’s job is to provide accurate time on your network and there are many services that rely on accurate time to function correctly. NTP synchronizes the clock across your network so that time is as accurate as possible. It’s an application layer protocol and it uses UDP as the transport layer protocol. Network time servers get their time from atomic clocks.

On systemd you can enable NTP synchronization using timedatectl.

sudo timedatectl set-ntp true

The above command will start and enable the systemd-timesyncd service. Now check the status.

timedatectl status

output:

               Local time: Fri 2022-05-20 21:45:34 +08
           Universal time: Fri 2022-05-20 13:45:34 UTC
                 RTC time: Fri 2022-05-20 13:45:34
                Time zone: Asia/Singapore (+08, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

You can see that system clock is synchronized and NTP service is enabled. To check the status of timesyncd:

sudo systemctl status systemd-timesyncd

Output:

● systemd-timesyncd.service - Network Time Synchronization
  Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Active: active (running) since Mon 2022-05-09 17:47:54 CST; 1h 37min ago
    Docs: man:systemd-timesyncd.service(8)
Main PID: 2243 (systemd-timesyn)
  Status: "Synchronized to time server 202.112.29.82:123 (0.arch.pool.ntp.org)."
   Tasks: 2 (limit: 512)
  CGroup: /system.slice/systemd-timesyncd.service
  └─2243 /usr/lib/systemd/systemd-timesyncd

Chrony

If the system clock can’t be synced to an NTP server, you can also try chrony, which is a versatile implementation of the Network Time Protocol. Run the following command to install it. (Note: If your system has the systemd-timesyncd pacakge, chrony will remove it from your system.).

  • Debian/Ubuntu: sudo apt install chrony
  • CentOS/RHEL/Fedora: sudo dnf install chrony
  • Arch Linux: sudo pacman -S chrony
  • OpenSUSE: sudo zypper install chrony

After it’s installed, start it with:

sudo systemctl enable --now chrony

Check its status:

sudo systemctl status chrony

Sample Output

 chrony.service - chrony, an NTP client/server
     Loaded: loaded (/lib/systemd/system/chrony.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-04-21 23:40:55 CST; 4 weeks 0 days ago
       Docs: man:chronyd(8)
             man:chronyc(1)
             man:chrony.conf(5)
    Process: 11030 ExecStart=/usr/lib/systemd/scripts/chronyd-starter.sh $DAEMON_OPTS (code=exited, status=0/SUCCESS)
   Main PID: 11039 (chronyd)
      Tasks: 2 (limit: 3676)
     Memory: 1.4M
        CPU: 168ms
     CGroup: /system.slice/chrony.service
             ├─11039 /usr/sbin/chronyd -F 1
             └─11040 /usr/sbin/chronyd -F 1

Apr 21 23:40:55 systemd[1]: Starting chrony, an NTP client/server...
Apr 21 23:40:55 chronyd[11039]: chronyd version 4.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +NTS +SECHASH +IPV6 -DEBUG)
Apr 21 23:40:55 chronyd[11039]: Using right/UTC timezone to obtain leap second data
Apr 21 23:40:55 chronyd[11039]: Loaded seccomp filter (level 1)
Apr 21 23:40:55 systemd[1]: Started chrony, an NTP client/server.
Apr 21 23:41:12 chronyd[11039]: Selected source 38.229.62.9 (0.ubuntu.pool.ntp.org)
Apr 21 23:41:12 chronyd[11039]: System clock wrong by 2496258.787751 seconds
May 20 21:05:31 chronyd[11039]: System clock was stepped by 2496258.787751 seconds
May 20 21:05:31 chronyd[11039]: System clock TAI offset set to 37 seconds

As you can see, chrony found the system clock is wrong and automatically sync it with the network time server (0.ubuntu.pool.ntp.org).

Rate this tutorial
[Total: 31 Average: 4.7]

10 Responses to “How to Configure Time Zone and System Clock in Linux

  • Michael
    2 years ago

    I learn something every time I read your posts, no matter how mundane I imagine the topic to be. Thank you!

  • 1. How does one add place names to the pick list of time zones, For example, USA Central Time typically only has Chicago and maybe Houston. There are lots of places in Central Time Zone that might appeal to my clients.

    2. I tried to subscribe using the pop-up request and got JSON errors. (I have a screen grab)
    How do I report these errors?

    Thanks in advance,
    ~~~ 0;-Dan

  • Steve Branch
    5 months ago

    When I enter:

    $ sudo timedatectl set-ntp true

    I get:

    Failed to set ntp: NTP not supported

    I wonder why I cannot run NTP.

    • Steve Branch
      5 months ago

      I may have found the answer. I am running Ubuntu 20.04 on a desktop, not a server.

    • Xiao Guoan (Admin)
      5 months ago

      You can try chrony:

      sudo apt install chrony
  • Thank you LinuxBabe

    hoping it will help with time issues on FT8 hamradio.

  • Jouni "rautamiekka" Järvinen
    5 months ago

    If you don’t wanna ppl run a command before hitting Tab, don’t say “run this command”, say something like “type this command”.

  • How about the command timedatectl set-timezone?

    • Xiao Guoan (Admin)
      5 months ago

      Yes, if your Linux system uses systemd, you can list time zones with:

      timedatectl list-timezones

      Then set a time zone like so:

      timedatectl set-timezone America/Chicago

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here