Setting the date and time accurately is essential on any device to manage your tasks. For instance, the correct date and time on a computer will help you automate your recurring tasks and save a lot of time. Additionally, when it comes to using internet services, accurate date and time plays an important role.

Although it doesn’t seem to be a problem on any operating system, Linux systems come with a bit of difficulty in that regard. In this article, we decided to lay out a complete guide about checking out, setting, and changing date and time on Linux operating systems. Don’t worry; it’ll only take a few steps and is all about learning a dozen command lines using the timedatectl command.

Stay tuned till the end!

How accurate is Linux system time?

Linux manages time based on UTC (Coordinated Universal Time) like other operating systems by default. Then it uses your location to change the UTC to your local time. So, the date and time shown on Linux are accurate and follow your local area internet to adjust the proper time.

Overall, Linux mainly uses two kinds of clocks to keep track of time:

  • A hardware clock called a real-time clock (RTC) that is built into your computer’s motherboard. It solely depends on computer hardware to run. As a result, shutting down the software won’t affect its operation.
  • A software clock integrated by the Linux kernel. It operates based on the real-time clock and your regional time zone. When the computer boots up, the software clock first uses UTC and then converts it to your local time to display the correct date and time on the desktop.

How to check the current time and date on Linux?

To change the date and time on Linux, you first need to list the current time and see whether it needs to be changed. To do so, you only need to enter as the root user to your system and execute a simple command that lists the local, universal, and RTC time, in addition to confirming whether the system clock is synchronized and whether NTP services are active.

All you need to do is to run the following command in the shell prompt and hit Enter:

timedatectl

However, if you only want to check the date and time without any extra information, run the following command:

date

This command shows the current date, day of the week, and time.

List current Hardware Clock

The previous commands only show the software clock, as we explained earlier. However, if you want to check the Hardware Clock, use one of the following commands:

sudo hwclock -‌-show

sudo hwclock -‌-show -‌-utc

sudo hwclock -‌-show -‌-utc -‌-verbose

sudo hwclock -r

How can I change my Linux system’s date and time?

Now that you know the current time and date, if it is misadjusted or wrong in any way, use the syntax we lay below to readjust it. Keep in mind that you should sign in as a root user to be able to run these commands.

date -s “date time”

date -‌-set=“date time”

Suppose you want to change the date and time to April 5, 2023 10:00:00; run the following command:

date -s “5 April 2023 10:00:00”

date -‌-set=“5 April 2023 10:00:00”

If you only want to set a date, run this command:

date +%Y%m%d -s “20230405”

On the other hand, to only set the time, run the following command:

date +%T -s “10:00:00”

If your time is set to 12 hours, to specify the AM or PM period, add %p to the time command:

date +”%T%p” -s “10:00:00PM”

Change the date and time using timedatectl command

In most modern systems, especially system-based Linux systems, you have to run the timedatectl command to adjust time and date. So, in that case, use the following syntax to change the date:

timedatectl set-time ‘YYYY-MM-DD’

sudo timedatectl set-time ‘YYYY-MM-DD’

For example, to change the date to Oct 5, 2023, use the following:

timedatectl set-time ‘2023-10-05’

sudo timedatectl set-time ‘2023-10-05’

This command will change the date as specified. But it will also readjust the time to 00:00, midnight. To avoid that, you can specify the time as well:

timedatectl set-time ‘YYYY-MM-DD HH:MM:SS’

For example:

timedatectl set-time ‘2023-10-05 06:23:51’

How can I set the time zone on Linux?

To set the time zone, first, you need to execute the following command to review all available time zones:

timedatectl list-timezones

You’ll see a list of countries and cities after running this command. Use the up-arrow or B key to scroll up the list and the down-arrow or F key to scroll down the list. After identifying your time zone, use the following syntax to adjust it:

timedatectl set-timezone Country/City

For instance, if you want to set your time zone to US, Florida, use the following command:

timedatectl set-timezone US/Florida

? Unleash your website's true potential with our cutting-edge Linux VPS hosting solutions! Scale effortlessly and reach new heights in the digital world. ???

How can I adjust the Hardware Clock on Linux?

In order to change the hardware clock from the system clock, issue one of the following commands:

hwclock -‌-systohc

hwclock -w

On the other hand, to change the system clock from the hardware clock, use the following syntax:

hwclock -‌-hctosys

hwclock -s

Synchronizing the system clock with a remote server using NTP

At last, if you don’t want to change your system’s time manually and sync it with a remote server, you can use the following command:

sudo timedatectl set-ntp yes

Then the system will want your verification. Use the command timedatectl to accept the changes.

Note that activating NTP (Network Time Protocol) will prevent you from changing the date and time using timedatectl command. If you want to disable it again, use the following command:

sudo timedatectl set-ntp false

Bottom line

This article lists all the necessary commands to adjust your Linux system’s date and time. Note that you need to sign in as a root user to be able to make changes to your system. Nevertheless, you may need more time-related commands to learn more about your system and do your tasks. In that case, use the following command to get help:

timedatectl help

In addition, run the following command to check command timedatectl man pages and get a more comprehensive coverage:

man timedatectl

People also read: