How to Set Time, Timezone and Synchronize System Clock Using timedatectl Command

The timedatectl command is a new utility for RHEL/CentOS 7 and Fedora 21+ based distributions, which comes as a part of systemd system and service manager, a replacement for old traditional date command used in sysvinit daemon based Linux distributions.

Set System Time, Date and Timezone in Linux

Use timedatectl to Set System Time, Date and Timezone in Linux

The timedatectl command allows you to query and change the configuration of the system clock and its settings, you can use this command to set or change the current date, time and timezone or enable automatic system clock synchronization with a remote NTP server.

In this tutorial, am going to take you through the ways you can manage time on your Linux system by setting the date, time, timezone and synchronize time with NTP from the terminal using new timedatectl command.

It is always a good practice to maintain the correct time on your Linux server or system and it can have the following advantages:

  1. maintain a timely operation of system tasks since most tasks in Linux are controlled by time.
  2. correct time for logging events and other information on the system and many more.

How to Find and Set Local Timezone in Linux

1. To display the current time and date on your system, use the timedatectl command from the commandline as follows:

# timedatectl  status
Check Time and Date

Check Time and Date

In the scrrentcast above, RTC time: is the hardware clock time.

2. The time on your Linux system is always managed through the timezone set on the system, to view your current timezone, do it as follows:

# timedatectl 
OR
# timedatectl | grep Time
Check Linux Time Zone

Check Linux Time Zone

3. To view all available timezones, run the command below:

# timedatectl list-timezones
List All Timezones in Linux

List All Timezones in Linux

4. To find the local timezone according to your location, run the following command:

# timedatectl list-timezones |  egrep  -o “Asia/B.*”
# timedatectl list-timezones |  egrep  -o “Europe/L.*”
# timedatectl list-timezones |  egrep  -o “America/N.*”
Find Local Timezone in Linux

Find Local Timezone in Linux

5. To set your local timezone in Linux, we will use set-timezone switch as shown below.

# timedatectl set-timezone “Asia/Kolkata”
Set Local Timezone in Linux

Set Local Timezone in Linux

It is always recommended to use and set the coordinated universal time, UTC.

# timedatectl set-timezone UTC
Set UTC Time in Linux

Set UTC Time in Linux

You need to type the correct name timezone other wise you may get errors when changing the timezone, in the following example, the timezone “Asia/Kalkata” is not correct therefore causing the error.

Set Correct Timezone in Linux

Set Correct Timezone in Linux

How to Set Time and Date in Linux

6. You can set the date and time on your system, using the timedatectl command as follows:

Set Time in Linux

To set time only, we can use set-time switch along the format of time in HH:MM:SS (Hour, Minute and Seconds).

# timedatectl set-time 15:58:30
Set Local Time in Linux

Set Local Time in Linux

Set Date in Linux

7. To set date only, we can use set-time switch along the format of date in YY:MM:DD (Year, Month, Day).

# timedatectl set-time 20151120
Set Date in Linux

Set Date in Linux

8. To set both date and time:

# timedatectl set-time '2015-11-20 16:14:50'
Set Date and Time in Linux

Set Date and Time in Linux

How to Find and Set Hardware Clock in Linux

9. To set your hardware clock to coordinated universal time, UTC, use the set-local-rtc boolean-value option as follows:

First Find out if your hardware clock is set to local timezone:

# timedatectl | grep local

Set your hardware clock to local timezone:

# timedatectl set-local-rtc 1
Set Hardware Clock Timezone

Set Hardware Clock Timezone

Set your hardware clock to coordinated universal time (UTC):

# timedatectl set-local-rtc 0
Set Hardware Clock to UTC

Set Hardware Clock to UTC

Synchronizing Linux System Clock with a Remote NTP Server

NTP stands for Network Time Protocol is a internet protocol, which is used to synchronize system clock between computers. The timedatectl utility enables you to automatically sync your Linux system clock with a remote group of servers using NTP.

Please note that, you must have NTP installed on the system to enable automatic time synchronization with NTP servers.

To start automatic time synchronization with remote NTP server, type the following command at the terminal.

# timedatectl set-ntp true

To disable NTP time synchronization, type the following command at the terminal.

# timedatectl set-ntp false

Summary

These are very easy examples described in this tutorial and I hope you will find them helpful for setting various Linux system clocks and timezones. To learn more about this tool, head over to timedatectl man page.

If you have anything to say about this article, feel free to leave a comment for any more information to add. Stay connected to Tecmint.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

12 Responses

  1. Harshal Wagh says:

    I have one doubt.

    Lets say if i have 2 system and both are in same time zone have “System clock synchronized: yes” or “NTP synchronized: yes” . so does it mean both systems the have exact times.

  2. Roger says:

    Thanks for the examples this helped me to quickly set up ntp synchronization.

    One issue found on a minimal Centos7 server install was:

    # timedatectl set-ntp true
    Failed to set ntp: NTP not supported.
    

    The solution was to install chrony. After that the set-ntp true command worked.

    # yum install chrony
    
  3. Tim says:

    Tip:

    I had problems setting my timezone, e.g.

    # timedatectl set-timezone Europe/Berlin
    

    resulted in

    Failed to set time zone: Invalid time zone 'Europe/Berlin'
    

    though this is listed by timedatectl list-timezones.

    Solution:
    The actual files to which the program timedatectl puts a symlink are very few. E.g.

    ls /usr/share/zoneinfo/Europe/
    

    only lists 3 cities, one for each available timezone in Europe. So find your timezone city (e.g. Paris for Berlin, Copenhagen etc.) and set this if you encounter the same issue.

  4. Logixor says:

    And ofcourse we set “timedatectl set-ntp true” and it magically works, but who sets the desired server, where, how. This is a big mess. Having the systemd and having to manually add the servers to the “/etc/systemd/timesyncd.conf” just looks wrong.

    Also the timestamp of “/etc/systemd/timesyncd.conf” is used for the internal workings of the timedatectl and guess what, if you manually modify this file you will actually change its timestamp. Really, this is a big huge mess.

  5. Brett E says:

    Hello,

    I did the following,

    # timedatectl set-ntp true
    

    But afterwards, the file /etc/systemd/timesyncd.conf, still had the Time servers commented out,

    [Time]
    #Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org

    My question is, does the timesyncd.conf file have to be edited after running, timedatectl set-ntp true ?

    Thank you.

    • Aaron Kili says:

      @Brett

      The default the internet cluster of ntp servers will be used. Unless you want to use the specified servers in /etc/systemd/timesyncd.conf, you can leave the time servers commented out.

  6. dn says:

    Has the software been tested for edge cases, eg UTC+13?

  7. dn says:

    These animated printouts are not an improvement – it looks cute, but the user has to wait to read what interests, and goes elsewhere.

    • eehh says:

      I had the very same thought about the animated examples since I came here just for a quick glance at timedatectl syntax and was turned off by visual bloat. Ironically, there’s a typo in item #8 — and the correct syntax can be seen in the GIF.

Leave a Reply to Logixor Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.