This simple tutorial will show you how to view, set, or update the time and date on your Linux system.
Find out the Current Time and Date
Before you change the time and date, it’s worth checking what it’s currently set to – it may already be correct!
The following command will display information about the time and timezone as it is currently set on your system:
The returned information will look something like this:
Local time: Mon 2021-08-02 12:27:41 BST Universal time: Mon 2021-08-02 11:27:41 UTC RTC time: Mon 2021-08-02 11:27:41 Time zone: Europe/London (BST, +0100) System clock synchronized: yes NTP service: active RTC in local TZ: no
The time and date as set on your system are displayed on the 1st line.
Also, note the RTC time on your system – this is the time stored in the hardware clock so that the correct time is maintained after your system loses power.
Changing/Setting the Timezone in Linux
Now we know what the date/time is and what it needs to be set to, it can be changed. Again, the timedatectl command comes to the rescue:
To set the date only, the following syntax should be used:
sudo timedatectl set-time YYYY-MM-DD
sudo timedatectl set-time '2021-06-21'
To set the time only, use the following syntax:
sudo timedatectl set-time HH:MM:SS
sudo timedatectl set-time '13:15:11'
To set both the date and time, use the following syntax:
sudo timedatectl set-time YYYY-MM-DD HH:MM:SS
sudo timedatectl set-time '2021-06-21 13:15:11'
Note the use of sudo – changing the system timezone requires root/administrative privileges.
Confirm the change by again running:
Keeping the Correct Date/Time Correct Using NTP
It’s pretty standard now to keep your system clock synchronized with a time server online, ensuring it’s always correct. This is done using the NTP (Network Time Protocol).
Your Linux system should come with a public time server pre-configured – you can enable it by running:
sudo timedatectl set-ntp yes
And your clock will be periodically synchronized with the correct time/date supplied by a public NTP server.
You can view the full user manual for timedatectl by running: