How to change date and time in RedHat/CentOS 7 with Best Example

In this tutorial, I will take you through the different ways to change date and time in RedHat/CentOS 7. Sometimes it is very important to have correct date and time in your Linux Server.

Change Date and Time

timedatectl is the command to change date and time in RedHat/CentOS7. We will go through different examples of this command to understand it further.

How to change date and time in RedHat/CentOS 7 with Best Example 1

To check current time and date

Current date and time can be checked by using timedatectl command.

[root@localhost ~]# timedatectl
Local time: Mon 2019-12-02 00:36:36 EST
Universal time: Mon 2019-12-02 05:36:36 UTC
RTC time: Mon 2019-12-02 05:36:32
Time zone: America/New_York (EST, -0500)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2019-11-03 01:59:59 EDT
Sun 2019-11-03 01:00:00 EST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2020-03-08 01:59:59 EST
Sun 2020-03-08 03:00:00 EDT

To check the version of timedatectl tool

Use –version with timedatectl command to check the installed version details of this tool.

[root@localhost ~]# timedatectl --version
systemd 219
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN

To List out the available Time Zones

You can check all the available time zones by using timedatectl list-timezones command.

[root@localhost ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
Africa/El_Aaiun
Africa/Freetown
Africa/Gaborone
................

To list out only Asia Time Zones

You can filter out the time zones you want to check from timedatectl list-timezones command as mentioned below.

[root@localhost ~]# timedatectl list-timezones | grep -i Asia
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Atyrau
Asia/Baghdad
Asia/Bahrain
Asia/Baku
Asia/Bangkok
Asia/Barnaul
Asia/Beirut
Asia/Bishkek
Asia/Brunei
Asia/Chita
Asia/Choibalsan
Asia/Colombo
Asia/Damascus
Asia/Dhaka
Asia/Dili
Asia/Dubai
...........

To change timezone to Asia/Dubai

Here, you can change the timezone by using timedatectl set-timezone command and specify the correct time zone from above output of timedatectl list-timezones command.

Advertisements
[root@localhost ~]# timedatectl set-timezone Asia/Dubai
[root@localhost ~]# timedatectl
Local time: Mon 2019-12-02 10:01:40 +04
Universal time: Mon 2019-12-02 06:01:40 UTC
RTC time: Mon 2019-12-02 06:01:36
Time zone: Asia/Dubai (+04, +0400)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

To change the time to 14:35:34

You can also change the time without changing the date by using timedatectl set-time command.

[root@localhost ~]# timedatectl set-time '14:35:34'
[root@localhost ~]# date
Mon Dec 2 14:35:36 +04 2019

To change the date to 3rd Dec,2019 and time to 14:35:34

You can change date and time both by using same timedatectl set-time command as mentioned below.

[root@localhost ~]# timedatectl set-time '2019-12-03 14:35:34'
[root@localhost ~]# date
Tue Dec 3 14:35:35 +04 2019

Note: Sometime you might observe an error “Failed to set time: Automatic time synchronization is enabled” whenever you try to change date and time manually. In that case you need to disable the NTP and then try to change date and time again.

[root@localhost ~]# timedatectl set-ntp 0

[root@localhost ~]# timedatectl
Local time: Tue 2019-12-03 14:37:33 +04
Universal time: Tue 2019-12-03 10:37:33 UTC
RTC time: Tue 2019-12-03 10:37:33
Time zone: Asia/Dubai (+04, +0400)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a

 

Also Read: How to enable ssh on Ubuntu

Reference: timedatectl man page

Advertisements

Leave a Reply