In CentOS 7, the command line tool for setting the date, time, and timezone is timedatectl
.
To set the date, use the following command:
timedatectl set-time YYYY-MM-DD
For example, to set the date to January 1st, 2022, you would use the command:
timedatectl set-time 2022-01-01
To set the time, use the following command:
timedatectl set-time HH:MM:SS
For example, to set the time to 3:30 PM, you would use the command:
timedatectl set-time 15:30:00
To set the time zone, use the following command:
timedatectl set-timezone timezone
For example, to set the time zone to Eastern Standard Time (EST), you would use the command:
timedatectl set-timezone America/New_York
To check the current date and time, you can use the timedatectl status
command.
If you want to synchronize your system time with a remote NTP server you can use the ntpdate
command and set the NTP server you want to sync with.
ntpdate pool.ntp.org
or
ntpdate time.nist.gov
It's also possible to configure NTP daemon (ntpd) to keep the clock synchronized in the background.
systemctl start ntpd
systemctl enable ntpd
Overall, timedatectl
is a powerful command-line tool that allows you to easily set and manage the date, time, and timezone on your CentOS 7 system.