The best way to Set the Date and Time on Linux

Keeping the software on your device up to date is an important part of a robust and secure system, but more important is the current time and date.

Accurate time and date on a system not only tells you the correct time, it also enables you to perform automated tasks as expected and seamlessly connect to services over the Internet.

This guide will show you how to check, adjust, and configure the time and date on Linux from the command line with the command timedatectl Command.

How time is managed on Linux

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

  • A real-time clock (RTC) or hardware clock that is integrated into the circuit board of your computer and runs independently of the operating system. The clock will continue to run even if your operating system is shut down, restarted, or hibernated.

  • A system clock, also popularly known as a software clock. The system clock is managed by the Linux kernel and depends on the real-time clock to get its starting time when you boot your Linux operating system.

By default, your system time is saved in Coordinated Universal Time (UTC) format. Your Linux system will then convert the UTC time to the correct local time based on your region or time zone. The local time is displayed on the desktop.

List time and date information

One of the most important things you should be able to do while configuring the time on Linux is being able to list and verify the current time on your system.

MAKEUSEO VIDEO OF THE DAY

To view the time and other configuration parameters, simply run the timedatectl Command without parameters as follows:

timedatectl

The command displays the system's local time, UTC time and the real-time clock. The output also lists the time zone and other important time-related parameters.

How to adjust the time on Linux

To set or change the time, use the timedatectl Command along with the set the time Subcommand.

sudo timedatectl set-time hh: mm: ss

note: You need elevated permissions to set the time or date.

In the above command, the 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 12:00 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 cannot change the time or date if Network Time Protocol (NTP) is enabled on your system.

How to enable / disable NTP

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

Run the following command to disable NTP on Linux:

sudo timedatectl set-ntp false

To reactivate or enable NTP, simply do the following:

sudo timedatectl set-ntp true

After activation, the system automatically adjusts the time and synchronizes it with the configured server time.

note: The set-ntp Subcommand will not work if your system does not support NTP.

How to set the date on Linux

To change the date on your computer, you can use the timedatectl Command with the set the time Subcommand in the following format:

sudo timedatectl set-date 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, enter the following command:

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

Note that we have also specified the time, because if you only specify the date, timedatectl will automatically set the time to 00:00, i.e. H. 12 midnight.

Change your time zone

Before you can go any further and change the time zone on your PC, it is important that you know how to list or view available time zones.

timedatectl list-timezones

Use the F. Key on your keyboard to scroll forward and the B. to scroll backward through the listed time zones. Alternatively, you can use the arrow keys to scroll.

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

timedatectl set-timezone Africa / Blantyre

Get command line help

To learn more about timedatectl, enter the following command:

timedatectl help

For a more complete description of the command, you can read the man pages by running:

Man timedatectl

Related: Ways to Get Command Line Help on Linux

Alternative utilities for the time switch under Linux

This guide showed you how to configure the time and date on Linux using the timedatectl utility, a powerful and modern clock setting included as part of the systemd Service. Other traditional utilities for configuring the clock on Linux are the hwclock and date Commands.

9 practical examples of the Linux date command

Do you need detailed information about the date and time on Linux? These date command examples will definitely help you out.

Continue reading

About the author

Mwiza Kumwenda
(39 published articles)

Mwiza is a professional developer of software and writes extensively on Linux and front-end programming. His interests include history, economics, politics, and corporate architecture.

More
By Mwiza Kumwenda

Subscribe to our newsletter

Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive offers!

Click here to subscribe

Leave a Reply

Your email address will not be published.