Keeping your software up to date is an important part of having a robust and secure Linux system, but even more important is having an up-to-date time and date.

Accurate time and date on a system not only tell you the correct time but also allows you to execute automated tasks as expected and connect to services over the internet seamlessly.

Let's look at how you can review, adjust or change, and set the time and date on Linux from the command line using the timedatectl command.

How Time Is Managed on Linux

To keep accurate time, Linux uses two different kinds of clocks :

  • A real-time clock (RTC) or hardware clock integrated into your computer's circuit board runs independently of the operating system. The clock still runs even when your operating system is shut down, rebooting, or hibernating.
  • A system clock is also popularly known as a software clock. Maintained by the Linux kernel, the system clock depends on the real-time clock to get its initial time when your Linux OS is booting up.

By default, your system time is kept in the Universal Coordinated Time (UTC) format. Your Linux system then converts the UTC to the correct local time based on your region or time zone. The local time is what's displayed on the desktop.

Listing Time and Date Information

Before you proceed to change the time on your Linux system. you must be able to list or check the current time.

To show the time and date, simply run the timedatectl command without any parameters as follows:

        timedatectl
    
timedatectl command output on Linux

The command displays the system's local time, the UTC, and the real-time clock. The time zone and other important time-related parameters are also listed in the output. Alternatively, you can view the time and date using the date command.

How to Adjust or Change the Time on Linux

To set or change the time, use the timedatectl command together with the set-time subcommand:

        sudo timedatectl set-time hh:mm:ss
    

You need to have elevated privileges to set the time or date.

In the aforementioned command, hh stands for hours, mm for minutes, and ss for seconds. The time you specify should be in the 24-hour format.

For example, to set the time to midnight, run the following command:

        sudo timedatectl set-time 00:00:00
    

The command updates both the real-time clock and the system or software clock. However, you will fail to change the time or date if Network Time Protocol (NTP) is enabled on your system.

How to Enable/Disable NTP on Linux

Network Time Protocol helps you in making sure that your time is synchronized with a remote server based on your time zone or region.

To disable NTP on Linux, run the following command:

        sudo timedatectl set-ntp false
    

To reactivate or enable NTP, simply run:

        sudo timedatectl set-ntp true
    

Once enabled, the system will automatically adjust and synchronize the time with the configured server time.

The set-ntp subcommand will not work if your system doesn't support NTP.

How to Set the Date on Linux

To change the date on your computer, you can run the timedatectl command with the set-time subcommand in the following format:

        sudo timedatectl set-time YYYY-MM-DD
    

...where YYYY is the year, MM is the month, and DD is the day.

For example, to change the date to January 1, 2000, issue the following command:

        sudo timedatectl set-time "2000-01-01 23:00:01"
    

We've also specified the time because when you only specify the date, timedatectl will automatically set the time to 00:00, i.e. midnight.

Changing Your Time Zone on Linux

Before you change the time zone on your PC, you must know how to list or view available time zones.

        timedatectl list-timezones
    
output of listing timezones on linux

Use the F key on your keyboard to scroll forward and the B key to scroll backward through the listed timezones. Alternatively, you can use the arrow keys for scrolling.

Once you identify your time zone, you can, for example, switch to the Africa/Blantyre time zone using the following command:

        timedatectl set-timezone Africa/Blantyre
    

Getting Command-Line Help

To learn more about timedatectl, issue the following command:

        timedatectl help
    

For more comprehensive coverage of the command, you can check out its man pages by running:

        man timedatectl
    

Alternative Time Clock Utilities on Linux

You can use timedatectl to change or set the date and time on Linux. The utility works well regardless of whether you are on a server or workstation. The timedatectl utility is a powerful and modern clock adjustment tool that comes as a part of the systemd service.

Other traditional clock configuration utilities on Linux are the hwclock and date commands.