how to set the date & time on linux

How to Set the Date & Time on Linux (Debian, Ubuntu, etc.)

In most cases, the Linux operating system will set the date and time automatically, and it shouldn’t be an issue. But in some cases, like if you are just getting started or don’t have an Internet connection, it can be an issue. In this post, I’ll explain how to set the date & time on Linux (via the GUI or command lines).

NTP is enabled by default on Linux and will connect to an Internet server to set the date and time accordingly. It’s also possible to set the date and time manually, from the desktop environment or with the command “sudo date -s ‘YYYY-MM-DD HH:MM:SS’.

I will now guide you through the details of setting the date and time on Linux. I will also give you a solution that should help in most cases, whether you are using a desktop interface or not, or if your computer is connected to the Internet or not.

How are date & time set up by default on Linux?

On almost any Linux distribution, the date & time are set automatically via NTP. It stands for “Network Time Protocol”, and the idea is to sync the clock with another computer (generally from an online server).

During the system installation, the configuration wizard will only ask for your timezone and set the date and time automatically from there. So, in most cases, there is nothing else to do. If you have an Internet connection, the time will stay synced with the source server, and you don’t have to worry about it.

The goal of this tutorial is to show you how to set this up manually, for example, if your system is not connected to the Internet or if you set an incorrect timezone.

If you would like to learn more about NTP and clock synchronization on Ubuntu, you can click on this link to read my full tutorial on the topic.

Setting Date and Time on Linux (Desktop interface)

If you have a desktop environment on your system, the date and time configuration should be pretty easy, especially if you have Internet access. But let’s take a look at what you can do to set it correctly.

Get My Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Linux!

Use the installation wizard

As mentioned previously, with almost any Linux distribution, you’ll need to configure the timezone during the installation. In fact, even if you install a server edition of Debian (no GUI), the system will ask you the question.

Once the timezone is set, the operating system will synchronize the system date and time with an Internet server, and display the correct clock depending on your location. In most cases, you’ll be set after that. The Linux system will synchronize regularly with a time provider, and it should be ok.

Use the system settings

If you miss the installation wizard or need to change something in your current configuration, you can use the system settings. It might be slightly different depending on your desktop environment (GNOME, KDE, etc.), but you should be able to easily find it.

I will show you how to do this with Ubuntu / GNOME, but it’s very similar with other environments.

Open the system settings from the app launcher (or via the wheel icon in the top-right corner).
Find the “Date & Time” submenu in this tool. By default, you should see something like:

As you can see, it’s set to “Automatic Date & Time”, and uses the Internet to configure it.
From there, you can do two things:

  • Change the time zone: If you have Internet access, it’s better to keep the configuration like this. Just click on the timezone to change it if needed.
    It will show you a map, you just need to click on your location:
  • Switch to manual mode: If you don’t have Internet access, or maybe you want to set the time manually, you can disable “Automatic Date & Time” by clicking on the corresponding line.
    You’ll then have access to the “Date & Time” line (in gray on my previous screenshot) to set it manually:

This tool is pretty intuitive, so in most cases, you should be fine using it in any situation. Just know that you can do the same thing in a terminal (see next part).

So, if you don’t use GNOME, can’t find the options on your distribution or just don’t have a desktop environment, keep reading to see how to do it with command lines.

Get My Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Linux!

If you are looking for exclusive tutorials, I post a new course each month, available for premium members only. Join the community to get access to all of them right now!

Setting the Date and Time in the Command Line

If you are using a server edition or are connected via SSH, you don’t have access to these tools. Not to worry, there are similar alternatives while in the command line.

Show the current date

First thing first, you can use this command to display the current date and time:
date

Get My Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Linux!

You’ll get the long date format (date, time, timezone) according to your locale. It looks like:

Yep, it’s in French even if my system is in English ­čÖé

Disable NTP

As explained previously, NTP is enabled by default in most cases, even if you don’t have a desktop environment. When NTP is enabled, you can set the date & time manually.

If you want to set the date and time in the command line, you need to first disable NTP with:
sudo timedatectl set-ntp false
Once disabled, you can use the command I give you in the next section, and it should keep your entry as the current date/time.

And if you want to switch back to automatic date, just enable NTP again with:
sudo timedatectl set-ntp true

By the way, the command “timedatectl” allows you to quickly see the current configuration, it can be useful to remember it.

Change the date/time in one command

Here is the command to set the date and time manually:
sudo date -s 'DATE'
For example:
sudo date -s '2023-03-14 14:03:00'
The date is not required, you can also use:
sudo date -s '14:03:00'
It works the same way.

The date command will handle most date formats, but you can find more information on the GNU website here if you have any doubts.

Use the command “date” to check if it changed as expected:
date

This command is pretty common on all Linux distributions, so it should work even if you are not using a Debian-based distribution.

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

NTP and Timedatectl configuration

By the way, NTP and Timedatectl are the tools you might need to understand if you want to go a bit further on this topic. They are the reason why the time and date synchronization works with an Internet connection, but not so well without it.

NTP is the protocol used for time synchronization on a network, and timedatectl is the tool installed by default on most Linux distributions to manage it.

For example, even if your computer doesn’t have Internet access, but can access a local network with a time server, you can edit the configuration to synchronize it with your own server instead of a “random” Internet server.

I will not go into more detail about this, but I have a dedicated guide about NTP that you should definitely read if you are interested. For example, it’s mandatory to set up something like this when you use Active Directory or Samba (if your clock is out of sync by 5 minutes or more, you can’t log in to the server).

Once your initial system setup is done, you are ready to move to the next steps! Here are a few suggestions:

Get My Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Linux!

Additional Resources

Lost with the command line?
You don’t need to learn and remember everything, just download my cheat sheet where I explain the most important commands on Linux, with a brief explanation and some examples.
Download my free PDF cheat sheet.

VIP Community
If you just want to hang out with me and other Linux fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Python is a great language to get started with programming on any Linux computer.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.


This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Similar Posts