To change the time on centos, use the timedatectl command together with the set-time subcommand.
sudo timedatectl set-time hh:mm:ss
Note: You need to have elevated privileges to adjust the time or date.
In the above mentioned command, the hh stands for hours, mm for minutes, and ss for seconds. The time you specify should be in the 24-hour format.
For example, to set the time to 12 o’clock midnight, run the following command:
sudo timedatectl set-time 00:00:00
The command updates both the real-time clock and the system or software clock. However, you will fail to change the time or date if the Network Time Protocol (NTP) is enabled on your system.
How to Set the Date on Centos 7
To change the date on your computer, you can run the timedatectl command with the set-time subcommand in the following format:
sudo timedatectl set-time YYYY-MM-DD
where YYYY is the year, MM is the month, and DD is the day. For example, to change the date to January 1, 2000, issue the following command:
sudo timedatectl set-time “2011-01-01 23:00:01”
Note that we’ve also specified the time because when you only specify the date, timedatectl will automatically set the time to 00:00 i.e. 12 midnight.
Changing Your Time Zone on Linux Centos
Before you can proceed and change the time zone on your PC, it is important that you know how to list or view available time zones.
Use the F key on your keyboard to scroll forward and the B key to scroll backward through the listed timezones. Alternatively, you can use the arrow keys for scrolling. Once you identify your time zone, you can, for example, switch to the Africa/Blantyre time zone using the following command:
timedatectl set-timezone Asia/Kolkata
How to Enable/Disable NTP on Centos
The Network Time Protocol helps you in making sure that your time is synchronized with a remote server based on your time zone or region. To disable NTP on Linux, run the following command:
sudo timedatectl set-ntp false
To reactivate or enable NTP, simply run:
sudo timedatectl set-ntp true
Once enabled, the system will automatically adjust and synchronize the time with the configured server time.
Note: The set-ntp subcommand will not work if your system doesn’t support NTP.
Getting Command-Line Help
To learn more about timedatectl, issue the following command:
For more comprehensive coverage of the command, you can check out its man pages by running: