How to set Time, Timezone and System Clock in Linux CentOS, Fedora & RHEL using timedatectl

How to set Time, Timezone and System Clock in Linux CentOS, Fedora & RHEL using timedatectl

If you need to replace the default timezone of your Linux installation with your own timezone you can do that using the timedatectl command, a new utility for the distributions based on RHEL/CentOS 7 and Fedora. This handy tool comes shipped together with the systemd system and service manager, which is a replacement for old traditional date command used by the Linux distributions based upon the sysvinit daemon.

Using the timedatectl command the administrator can query and change the configuration of the system clock and its settings, such as changing the current date, time and timezone. In this post we’ll explain how to do that.

Show the current Time, Date and Time Zone

Let’s start with the command required to display the current time and date on our system:

Which will give us the following results:

How to set Time, Timezone and System Clock in Linux CentOS, Fedora & RHEL using timedatectl

The RTC time shown above is the hardware clock time.

The current timezone info is present together with the other system settings: if we want to show your current timezone only, we can filter these results with the following grep command:

List all available Time Zones

Here’s the command we can use to show all the available timezones (and find the one we want to set):

Which will return us a browsable list of time zones:

How to set Time, Timezone and System Clock in Linux CentOS, Fedora & RHEL using timedatectl

Browsing the full list by scrolling the terminal might be quite hard. To save our valuable time we can use the egrep command filtering out the available timezones for our location in the following way:

Set a new Time Zone

Here’s how we can modify our current timezone, replacing it with another one taken from the above list:

Set Time and Date

The timedatectl command can be also used to directly set the date and time on our system in the following way:

Set Time only

To set the system time we can use the set-time switch using the HH:MM:SS (Hours, Minutes, Seconds) format:

Set Date only

To set system date we can also use the set-time switch using the YYYY-MM-DD (Year, Month, Day) format:

Set Time and Date together

To set system time & date in a single shot we can use the set-time switch using the following format:

 

That’s about it!

We sincerely hope that this post will help many System Administrators who’re looking for a way to adjust the date, time, timezone & clock settings of their Linux system.

 

RELATED POSTS

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan