Setting time and date is also one of the important things for your machine, especially if you are using IPA/LDAP services on your Linux machine. This article will show you how to do it locally (be aware that with some actions you will disable time/date sync from outer sources).
Here is how to do it:
(execute all commands as root)
First, check status of your time and date settings by entering:
timedatectl status
Change time:
To set current time use the following command:
HH – hour (I will be using 24 hour format)
MM – minute
SS – seconds
timedatectl set-time HH:MM:SS
You will get error like I did “Failed to set time: NTP unit is active“if you already have set NTP service on your machine.
You can force your machine to use local time by typing in
sudo timedatectl set-local-rtc true
If you still cannot still change manually time even with set-local-rtc type in following
sudo timedatectl set-ntp false
However, be aware that this command will disable ntp and chrony service and after this you will depend on your manual time setting on local machine.
Change date:
We can change the date with following command:
sudo timedatectl set-time "yyyy-MM-dd hh:mm:ss"
yyyy – year
MM – month
dd – day
hh – hour
mm – minute
ss – seconds
Set the time also, otherwise your clock will be reset.
Change time zone:
First let’s check available time zones by typing in:
timedatectl list-timezones
Ok, I want to set time zone to Europe/Zagreb, to do so, I will enter
(change Europe/Zagreb with your time zone)
sudo timedatectl set-timezone Europe/Zagreb
You can also enable NTP service by entering following command (if you disabled NTP and want only local time from your machine you don’t want to enable NTP service)
sudo timedatectl set-ntp yes
More details on setting NTP server in other article