Red Hat Enterprise Linux 7 or CentOS 7 come with three default utilities or command line that help to configure and display the information about the system date and time:
3 Command to Change the Linux Date and Time in CentOS 7/RHEL 7
1.The timedatectl utility, which is new in Red Hat Enterprise Linux 7 and is part of systemd;
2.The traditional date command;
3.The hwclock utility for accessing the hardware clock.
The timedatectl utility is a part of the systemd system and service manager that allows you to change the current date and time of the linux system.
1.1. How to check time server linux using timedatectl ?
Run the timedatectl command with no additional command line options:
[root@centos7 ~]# timedatectl Local time: Mon 2014-11-03 22:44:24 MYT Universal time: Mon 2014-11-03 14:44:24 UTC RTC time: Mon 2014-11-03 14:44:24 Timezone: Asia/Kuala_Lumpur (MYT, +0800) NTP enabled: n/a NTP synchronized: no RTC in local TZ: no DST active: n/a
1.2. How to set date on centos sing timedatectl ?
timedatectl set-time YYYY-MM-DD
Example of change the current date :
[root@centos7 ~]# timedatectl set-time 2014-11-04
1.3. How to change server time centos using timedatectl ?
timedatectl set-time HH:MM:SS
Example of change the current time :
[root@centos7 ~]# timedatectl set-time 00:50:00
1.4. How to change the Time Zone using timedatectl ?
Use the following command to list all available time zones in Asia :
[root@centos7 ~]# timedatectl list-timezones | grep Asia Asia/Aden Asia/Almaty Asia/Amman Asia/Anadyr Asia/Aqtau Asia/Aqtobe Asia/Ashgabat Asia/Baghdad .. Asia/Kuala_Lumpur ..
In order to change the time zone to Asia/Kuala_Lumpur, type the following command as a root user :
[root@centos7 ~]# timedatectl set-timezone Asia/Kuala_Lumpur
The date utility is available on all Linux systems. date allows you to display and change the current date and time and it is frequently used in scripts to display the system clock.
2.1. How to display the current Date and Time using date ?
To display the current date and time, run the date command with no additional command line options:
[root@centos7 ~]# date Tue Nov 4 01:12:39 MYT 2014
This displays the day of the week followed by the current date, local time, abbreviated time zone, and year.
2.2. How to display the current Date and Time in customized the format ?
You can also customize the format of the displayed information by providing the +”format” option on the command line:
[root@centos7 ~]# date +"%Y-%m-%d %H:%M" 2014-11-04 01:20
2.3. How to change the current time using date ?
In order to change the current date and time, type the date command with the –set or -s option as a root user :
To change the current time, run the date command with the –set or -s option as root:
date +%T -s HH:MM:SS
Replace HH with an hour, MM with a minute, and SS with a second, all typed in a two-digit form.
As an example change the current time to 11:56 p.m., as a root, run the following command :
[root@centos7 ~]# date +%T --set 23:56:00
hwclock is a utility for accessing the hardware clock. Hardware clock is independent of the operation system you use and works even when the machine is shut down. This program is used to find out the time from the hardware clock and set the system time at boot time.
3.1 How to display the Current Date and Time using hwclock ?
To display the current date and time, run hwclock with no command line options as a root :
[root@centos7 ~]# hwclock Tue 04 Nov 2014 01:41:08 AM MYT -0.131049 seconds
3.2. How to change the current Date and Time using hwclock ?
In order to change the hardware clock date and time, you can do so by appending –set and –date options along with your specification:
hwclock --set --date "dd mmm yyyy HH:MM"
As an example, if we want to set the date and time to to “15:20, October 29, 2015”, run the command in the following format:
[root@centos7 ~]# hwclock --set --date "29 Oct 2015 15:20"
Note : In Red Hat Enterprise Linux 6 / CentOS 6, the hwclock command was run automatically on every system shutdown or reboot, but it is not in Red Hat Enterprise Linux 7 /CentOS 7.
For more information on how to change the Linux Date and time in Red Hat Enterprise Linux 7 and CentOS 7, please read the manual page for the timedatectl, date and hwclock.