OSETC TECH

CentOS 7 /RHEL 7: How To Change The Date And Time Using Timedatectl Command

In CentOS 7 or RHEL 7 system, A new command used to set date and time is “timedatectl“. this command is distributed as part of the systemd system and service manager. you can use this command to change the date and time, set the time zone, check the current date and time or others. In this post, you will learn how to:

#1 Displaying the current date and time using “timedatectl” command

#2 Changing the current date and time using “timedatectl” command

#3 Changing the TimeZone using “timedatectl” command

CentOS 7 Check The Current Date And Time

To check the current date and time for your system, you can just simply issue the “timedatectl” command in command line interface, type:

timedatectl

Outputs:

[root@devops ~]# timedatectl
  Local time: Thu 2018-07-05 14:14:54 UTC
Universal time: Thu 2018-07-05 14:14:54 UTC
RTC time: Thu 2018-07-05 14:14:54
Time zone: UTC (UTC, +0000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

From the above output of command “timedatectl”, you can see the local time of your system , Universal time, Real-time clock time(RTC), the current time zone, the status of the NTP synchronized, and others.

CentOS 7 Changing the Current Date Using “timedatectl”

If you want to change the current date for your system, just using “timedatectl” command with set-time option, type:

timedatectl set-time <YYYY-MM-DD>

Specified the value for “YYYY-MM-DD” like the following format: 2019-12-08.

Example: changing the current date to Dec 08 2019, type:

timedatectl set-time 2019-12-08

CentOS 7 Changing the Current Time Using “timedatectl”

To change the current time for your Centos 7 system, you can run the following  “timedatectl’ command with “set-time” option, type:

timdatectl set-time <HH:MM:SS>

Specified the value for “HH:MM:SS> like the following format: 10:24:34 (Hour:Minute:Second).

Example: changing the current time to 10:24:34, issue the below command:

timedatectl set-time 10:24:34

Outputs:

[root@devops Desktop]# date
Mon Dec  8 21:28:29 EST 2014

[root@devops Desktop]# timedatectl set-time 10:24:34

[root@devops Desktop]# date
Mon Dec  8 10:24:35 EST 2014

CentOS 7 Changing the TimeZone using “timedatectl” command

Before changing the time zone of system, you need to know all available time zones for your system, issue the following command:

timedatectl list-timezones

Outputs:

[root@devops Desktop]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
......

Searching a timezone you want to select, you can use grep command with timedatectl list-timezones, such as, find all available Europe time zone supported by your system, type:

timedatectl list-timezones | grep Europe

Outputs:

[root@devops Desktop]# timedatectl list-timezones | grep Europe
Europe/Amsterdam
Europe/Andorra
Europe/Athens
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Bucharest
Europe/Budapest
Europe/Busingen
Europe/Chisinau
Europe/Copenhagen
....

Now we can try to change the current time zone of your system, using the timedatectl command with the “set-timezone” command:

timedatectl set-timezone <timezone name>

Specified one time zone that you searched from the output of “list-timezones”, example, changing the time zone to “Europe/berlin”, type:

timedatectl set-timezone Eruope/berlin

Outputs:

[root@devops Desktop]# timedatectl | grep Timezone
Timezone: America/New_York (EST, -0500)

[root@devops Desktop]# timedatectl set-timezone Europe/Berlin

[root@devops Desktop]# timedatectl | grep Timezone
Timezone: Europe/Berlin (CET, +0100)