AMP AMP

How To Configure Time using timedatectl command

To Configure Time using timedatectl command

Configuring Timezone, Time and System Clock Synchronization using timedatectl Command in linux is explained in this article.

Find and Set Local Timezone in Linux

To display the current date and time on your system, utilize the following command in the commandline.


\[root@linuxhelp~\] # timedatectl  status

current date and time

Here, RTC time is the hardware clock time.
To view the present timezone, run the following command.


\[root@linuxhelp~\] # timedatectl 
OR
\[root@linuxhelp~\] # timedatectl | grep Time

Execute the below command inorder to view all available timezones.


\[root@linuxhelp~\] # timedatectl list-timezones


Execute the below command to find the local timezone in your location.


\[root@linuxhelp~\] # timedatectl list-timezones |  egrep  -o &ldquo Asia/B.\*&rdquo 
\[root@linuxhelp~\] # timedatectl list-timezones |  egrep  -o &ldquo Asia/K.\*&rdquo 

Utilize set-timezone for setting your local timezone in Linux.


\[root@linuxhelp~\] # timedatectl set-timezone &ldquo Asia/Kolkata&rdquo 
\[root@linuxhelp~\] # timedatectl

The coordinated universal time, UTC is mostly recommended.


\[root@linuxhelp~\] # timedatectl set-timezone UTC
\[root@linuxhelp~\] # timedatectl

While modifying the timezone, you have to type the correct name of the timezone, or else you will get an error.

Setting Date and Time in Linux

Utilize the set-time with the format of time in HH:MM:SS (Hour, Minute and Seconds).


\[root@linuxhelp~\] # timedatectl set-time 12:30:30 
\[root@linuxhelp~\] # timedatectl

Utilize the set-time with the format of date in YY:MM:DD (Year, Month, Day).


\[root@linuxhelp~\] # timedatectl set-time 2016-11-20
\[root@linuxhelp~\] # timedatectl

For setting both time and date utilize the following command.


\[root@linuxhelp~\] # timedatectl set-time ' 2016-11-20 19:08:14' 
\[root@linuxhelp~\] # timedatectl

To Find and Set Hardware Clock in Linux

Utilize the set-local-rtc boolean-value option to check whether your hardware clock is in local timezone.


\[root@linuxhelp~\] # timedatectl | grep local

To Set the hardware clock to local timezone


\[root@linuxhelp~\] # timedatectl set-local-rtc 1
\[root@linuxhelp~\] # timedatectl

To Set the hardware clock to coordinate universal time (UTC)


\[root@linuxhelp~\] # timedatectl set-local-rtc 0
\[root@linuxhelp~\] # timedatectl

< ads2>

Utilize the below command for Synchronisation with a Remote NTP Server


\[root@linuxhelp~\] # timedatectl set-ntp true
\[root@linuxhelp~\] # timedatectl

Utilize the following command for disabling NTP time synchronisation.


\[root@linuxhelp~\] # timedatectl set-ntp false
\[root@linuxhelp~\] # timedatectl

FAQ
Q
Is NTP UDP or TCP?
A
NTP time servers work within the TCP/IP suite and rely on User Datagram Protocol (UDP) port 123.
Q
Has the timedatectl software been tested for edge cases, eg UTC+13 ?
A
you can simply set the local timezone at UTC+13 timezone.
Q
Does the timesyncd.conf file have to be edited after running, timedatectl set-ntp true ?
A
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.
Q
I want NTP to be synced? How to enable that
A
Please set "timedatectl set-ntp true" as true in order to NTP.
Q
Which port does NTP use?
A
NTP uses port 123.