How to Use the timedatectl Command on Linux

Linux TimedatectlCommand allows you to set your date, time, and timezone for both your system clock as well as your real-time clock. Spare a moment, and we’ll show you how it all works.

It’s All Relative

Your computer’s treatment of time is one of those things that you might expect to be pretty straightforward. It is, at least, until you look deeper into it.

The Linux system clock counts down the number of seconds since. the Unix epoch. This was at 00:00:00 on Jan. 1, 1970, UTC. UTC stands for universally coordinated time, but it is also known as coordinated universal or universal time. This is the time standard that governs and regulates the world’s time. Different time zones use an offset from UTC to get their local time. Some time zones are ahead while others are below UTC.

Linux computers have a software-based system clock. It cannot run when the computer’s power is off. A battery-backed, hardware-based real time clock is also available that can run when the computer is turned off. It tells the system clock what time it’s whenever Linux boots up. Access to a network time protocol server (NTP) is not possible.

NTP servers are servers that provide precise time information to computers that request it. If you boot up your computer or laptop and there is no internet access—or it hasn’t been configured to use NTP servers—the real-time clock is used to prime the system clock instead of an NTP Server.

The system clock is always set to UTC. Any application that needs to obtain local time must:

  • Access the system clock to obtain UTC
  • Find out the time zone and use the correct offset
  • Consider whether daylight savings timeThis is in effect

The application is responsible for converting UTC to local times, and not the system clock. Or, more precisely, the application is responsible for the conversion. That’s why it is vital that your computer knows which timezone it is, what UTC time is, how many seconds have passed since the Unix epoch, and whether daylight savings time is in effect.

The following is the list of systemd-based Linux distributions. TimedatectlTo see or modify these settings and values, use the command

Timedatectl: How to Get Started

You can use the to view the current data and other values. TimedatectlCommand with the Status operator.

Timedatectl status

The output from the timedatectl command using the status operator

Actually, you can drop the status and you’ll still get the same output.

Timedatectl

The output from the timedatectl command with no operator

Both sets of output show:

  • Local Time: The time that the computer thinks it’s, according to its time zone.
  • Universal Time: The UTC time.
  • RTC Time: The time that the real-time clock uses. This is usually UTC.
  • Time zoneInformation regarding the time zone configuration.
  • System Clock SynchronizedWhether the system clock has been synchronized with an NTP Server.
  • NTP Service: Whether the computer’s NTP service is active.
  • RTC in the local TZWhether the real-time clock uses local time instead UTC.

You can see which time zones are available. TimedatectlYou can type commands to support command:

timedatectl list-timezones | wc -l

Counting the timedatectl time zones

That’s way more than there are timezones in the world. If you pipe the outputIn grep and filter out the entries for “America” and pipe that into lessWe can scroll through a smaller list.

timedatectl list-timezones | grep "America/" | less

Filtering out American time zones with grep

As you review that list you’ll see “America” is taken to have its widest possible meaning. The second thing you’ll notice is most of the entries aren’t actual time zones.

"American" time zone list in less

Setting the Time Zone

Take a look at the unfiltered list containing all time zones supported by Timedatectl you’ll see places as well as time zones. You can either specify a time zone by name, such as EST or GMT, or choose a location that is in the same time zone, such as London or New York.

Resetting your time zone isn’t something you’ll be doing often, but perhaps you’ve moved home or you’re working away for a while and want to localize your laptop. Pick a time zone where you would like to reset your time.

We’ll set this computer to mountain time, which is the same time zone as Edmonton. We’ll then see how the settings have changed.

Timedatectl set-timezone "America/Edmonton"
timedatectl

New time zone and time settings

Our time zone has changed, our local times have been modified, and our offset to UTC has increased.

RELATED: How to Use Pipes on Linux

Manually setting the date and time

Although manually setting the time and date is possible, usually you won’t need to. Using time synchronization and NTP is the preferred way to keep your computer’s time and date accurate. If you try to change your computers’ date or time you’ll probably get an error, telling you that time synchronization is in use.

timedatectl set-time 10:30:00

Error message because time synchronization is in force

This command can be used to disable the time synchronization services:

sudo systemctl stop systemd-timesyncd.service

You can set the date, time or both with the Timedatectl set-time operator. dates are in year-month-day order YYY-MM-DD, and time is in hours-minutes-seconds order HH:MM:SS. We’re going to set the time and date with this command:

Timedatectl set-time "2022-01-30 10:30:00"

We’ll then check that the changes have taken place, using Timedatectl.

timedatectl

Manually setting the time and date

The date and time have been changed. Note that the computer is using an incorrect UTC time. We’re also informed that the system clock is not being synchronized and the NTP service is inactive.

If you have internet connection, you can restore the time sync service so that the time can be retrieved and all details are reset.

sudo systemctl start systemd-timesyncd.service
Timedatectl

Restarting the NTP service and restoring the correct time values

RTC: UTC oder LTZ?

It’s possible to have your real-time clock set to your local time zone time instead of to UTC—possible, but inadvisable. If you make the change, you’ll see a warning about the dire effects this may have on your system in the future.

This is how to fix a problem with your machine’s time settings. This is how you set the real-time clock to UTC.

First, we’ll need to set it to the local time zone.

Timedatectl set-local-rtc 1

Then we’ll ask timedatectlIts status.

Timedatectl

Setting the real-time clock to the local time zone, and the warning that accompanies that

I think they’ve made their feelings clear.

Use this command to restore the UTC-real-time clock.

timedatectl set-local-rtc 0

It’s yours to set and forget

Unless you made an error during the installation of your Linux distribution, or you relocate there’s usually no reason to be modifying the settings of your system and real-time clocks.

Set the system clock to your time zone, the real-time clock to UTC, and make sure you’re system is polling a network time protocol server. That’s the default state after most installations.

If they’re all set, your computer’s time systems will look after themselves.

Leave a Reply

Your email address will not be published. Required fields are marked *