3 Command to Change the Linux Date and Time in CentOS 7/RHEL 7

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.

1. timedatectl Utility

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 ?

See also  How to Uninstall VMware Tools on Linux, Solaris, FreeBSD

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

2. date Utility

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 ?

See also  How to Enable and Grant Remote Access to MySQL Database Server

You can also customize the format of the displayed information by providing the +”format” option on the command line:

date +"format"

Example :

[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

3. hwclock Utility

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.

See also  How to Install scp Command on CentOS 6.2

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.

How to Reset the Directory Manager Password on RHEL 7 / CentOS 7
How to Reset the Directory Manager Password on RHEL 7 / CentOS 7

It is best practice to remember passwords, but because too many passwords, sometimes we forget. We are not encouraged to write the password on any paper or share the password...

How to Find Big Files Size on Linux RHEL/CentOS
How to Find Big Files Size on Linux RHEL/CentOS

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space. Low disk space can also...

Why Linux users should worry about malware and what they can do about it
Why Linux users should worry about malware and what they can do about it

Don’t drop your guard just because you’re running Linux. Preventing the spread of malware and/or dealing with the consequences of infection are a fact of life when using computers. If...

How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7
How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7

This short howto will explain the steps to reset a lost root password or to reset a forgotten root password on Linux RHEL 7 or CentOS 7. Basically, we will...

How to Update CentOS or Upgrade CentOS to the Latest Version
How to Update CentOS or Upgrade CentOS to the Latest Version

Recently, the latest version of CentOS 7.3 was released. All users of CentOS 7.0, 7.1 and 7.2 can upgrade their system to the most recent. This quick guide will explain...

How to Change your WordPress Username, Nickname and Display Name in MySQL
How to Change your WordPress Username, Nickname and Display Name in MySQL

After you create an account log in WordPress, you may want to change your WordPress username, as appropriate or due to security reason. However, you can not do this from...

How to Enable SSH Root Login on Ubuntu 16.04
How to Enable SSH Root Login on Ubuntu 16.04

As what we wrote in the previous article on how to allow SSH root on Ubuntu 14.04, after installing a fresh new copy of Ubuntu 16.04 LTS, we find that...

How to Change UUID of Linux Partition on CentOS 7
How to Change UUID of Linux Partition on CentOS 7

UUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system. If you cloned a virtual machine from vCenter, the metadata containing...

Leave a Reply

Your email address will not be published. Required fields are marked *