Table of Contents
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:
# timedatectl status
Which will give us the following results:
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:
# timedatectl | grep Time
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):
# timedatectl list-timezones
Which will return us a browsable list of time zones:
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:
# timedatectl list-timezones | egrep -o 'Asia/B.*'
# timedatectl list-timezones | egrep -o 'Europe/L.*'
# timedatectl list-timezones | egrep -o 'America/N.*'
Set a new Time Zone
Here’s how we can modify our current timezone, replacing it with another one taken from the above list:
# timedatectl set-timezone Europe/Rome
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:
# timedatectl set-time 20:15:30
Set Date only
To set system date we can also use the set-time switch using the YYYY-MM-DD (Year, Month, Day) format:
# timedatectl set-time 2017-12-30
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:
# timedatectl set-time '20:15:30 2017-12-30'
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.