Home » Linux » Linux Set Time

How to Set/Change the Date/Time in Linux

This simple tutorial will show you how to view, set, or update the time and date on your Linux system.

You may also want to check out our article on changing the timezone in Linux.

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:

timedatectl

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

For example:

sudo timedatectl set-time '2021-06-21'

To set the time only, use the following syntax:

sudo timedatectl set-time HH:MM:SS

For example:

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

For example:

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:

timedatectl

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:

man timedatectl

 

SHARE:
Photo of author
Author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment