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.

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:

  • maintain a timely operation of system tasks since most tasks in Linux are controlled by time.
  • 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

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

  1. 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

  1. To view all available timezones, run the command below:
# timedatectl list-timezones

Check Linux Time Zone

  1. 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.*”

  1. To set your local timezone in Linux, we will use set-timezone switch as shown below.
# timedatectl set-timezone “Asia/Kolkata”

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

# timedatectl set-timezone UTC

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.

How to Set Time and Date in Linux

  1. 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 Date in Linux

  1. 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

  1. To set both date and time:
# timedatectl set-time '2015-11-20 16:14:50'

Set Date and Time in Linux

How to Find and Set Hardware Clock in Linux

  1. 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 your hardware clock to coordinated universal time (UTC):

# timedatectl set-local-rtc 0

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

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

  • qq_43638135
    妲己再美究为妃: 博主没有想过自己接一些私活干吗?我现在还没毕业,但是我也确实听说外挂市场自动化游戏脚本市场挺火热的,并且报酬也很丰厚,但是具体的我也不是很清楚,求解答。 (1个月前 #47楼) 查看回复(2) 举报 回复
    22