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.

Linux doesn’t have to be intimidating. With my e-book, Master Linux Commands, you’ll uncover the secrets of the terminal in a fun, step-by-step journey. From basics to scripts, get ready to level up your Linux skills. Oh, and did I mention the handy cheat sheet you get as a bonus?

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.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

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.

Join Our Community!

Connect, learn, and grow with other Raspberry Pi enthusiasts. Support RaspberryTips and enjoy an ad-free reading experience. Get exclusive monthly video tutorials and many other benefits.

Learn more

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.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download 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:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

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 🙂

Want to know more about the date command on Linux? Click on the link for useful tips.

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:

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:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

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

Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.

Additional Resources

Overwhelmed with Linux commands?
My e-book, “Master Linux Commands”, is your essential guide to mastering the terminal. Get practical tips, real-world examples, and a bonus cheat sheet to keep by your side.
Grab your copy now.

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.

Similar Posts