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 the 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:
- maintain a timely operation of system tasks since most tasks in Linux are controlled by time.
- the 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 command line as follows:
# timedatectl status
Check Time and DateIn the screencast 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
3. To view all available timezones, run the command below:
# timedatectl list-timezones
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
5. To set your local timezone in Linux, we will use the set-timezone switch as shown below.
# timedatectl set-timezone "Asia/Karachi"
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
You need to type the correct name timezone otherwise you may get errors when changing the timezone, in the following example, the timezone “Asia/Kolkata” is not correct therefore causing the error.
Set Correct Timezone in LinuxHow 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 a set-time switch along with the format of time in HH:MM:SS (Hour, Minute, and Seconds).
# timedatectl set-time 15:58:30
Set Local Time in Linux
Set Date in Linux
7. To set date only, we can use a set-time switch along with the format of date in YY:MM:DD (Year, Month, Day).
# timedatectl set-time 20151120
Set Date in Linux
8. To set both date and time:
# timedatectl set-time '2015-11-20 16:14:50'