fix wrong date and time on raspberry pi

How to Set the Date & Time on Raspberry Pi (Desktop & Lite)

In most cases, the Raspberry Pi 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 on Raspberry Pi or don’t have an Internet connection, it can be an issue. In this post, we’ll learn how to set the date & time on Raspberry Pi.

NTP is enabled by default on Raspberry Pi OS 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 interface or with the command “sudo date -s ‘YYYY-MM-DD HH:MM:SS’.

I will now guide you through the details and give you a solution that should help in most cases, whether you are using a Desktop environment or not, or if your Pi is connected to the Internet or not.

If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.

Why are date and time an issue on Raspberry Pi?

On a computer, you’ll rarely think about setting the date and time correctly. You might configure it after the installation and then forget about it for years. But on Raspberry Pi, you might have an issue, especially when using it without the Internet, or not using a recent Raspberry Pi OS version.

The first reason is that Raspberry Pi OS relies on an Internet connection to get and keep the correct date and time.

On the desktop version, there are no ways to set the date and time directly in the Interface, the only thing you can change is the time zone.

But the other reason comes from hardware specificity.
On any computer, there is a battery that allows the computer to “remember” the date and time, even when disconnected from a power source for a long time. On Raspberry Pi, there isn’t such a thing.

Download the Pi Glossary!
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
Download now
Lithium battery on a computer motherboard

On recent Raspberry Pi OS versions (since Stretch I think), a package is included to fix this: “fake-hwclock”. It will store the current date and time in the operating system files, to restore it after a reboot if there is no Internet connection.

If you are using an older Raspberry Pi OS system, or a different operating system, it might be something to look at before going further, as I will not cover this case in the following.

Note: If you need a hardware clock, there is a way to add a module (like this one on Amazon) via the GPIO pins. I won’t explain this in detail here, but that’s something to think about for projects where time is important but where the Raspberry Pi is not connected to the Internet.

Setting Date and Time on Raspberry Pi OS with Desktop

If you are on Raspberry Pis OS, the date and time configuration should be pretty easy if you have Internet access. But let’s take a look at what you can do to set it correctly.

Use the welcome wizard

On the first boot on Raspberry Pi OS, a configuration wizard will show up and ask you for a bunch of information, including your location. Your Pi doesn’t ask for it out of curiosity, but to set the time zone according to your answer.

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 Raspberry Pi will synchronize regularly with a time provider, and it should be ok.

I have a complete guide on how to set up Raspberry Pi OS here, if you need a more in-depth step-by-step explanation.

Use the Raspberry Pi configuration tool

If you miss the welcome wizard or need to change something in your current configuration, you can use the Raspberry Pi configuration tool on your system.

In the main menu, go to Preferences > Raspberry Pi Configuration.
In the “Localisation” tab, you can change the current time zone:

Choose the one corresponding to your location, and click on “Ok” twice to save the changes.
A few seconds later, the time should be updated in the top-right corner.

On Raspberry Pi OS with a Desktop, this is the only control you have directly in the interface. You can set a different time zone, but can’t set the date and time manually. To manage this, you need to use the command line.

So, if these tips didn’t help you, keep reading to find other solutions.

Download the Pi Glossary!
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
Download now

If you are a bit lost on Raspberry Pi OS Desktop and need help getting started, I have a solution for you. My Raspberry Pi Bootcamp course will guide you through the first steps, from understanding the hardware to setting up your first OS as a Desktop replacement. You can find more details about it on this page.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Setting the Date and Time in the Command Line

If you are using Raspberry Pi OS Lite 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.

Use Raspi-config

The easiest way to fix your time zone is to use raspi-config, to get similar results quickly.
Raspi-config is the main configuration tool available on Raspberry Pi OS Lite, allowing you to configure many things, including date and time:

  • Start the tool with this command:
    sudo raspi-config
  • Got to “Localisation options”, then “Timezone”:
  • Pick a geographic area and a specific time zone:

Once done, the system configuration will be updated with the new date/time.

By the way, you can use this command to display the current date and time:
date

In one command

So, Raspi-config will help us to do the same thing as in the Desktop interface, but can’t still configure the date and time manually. The only way to set a custom date is to use the command line.

Here is the command to set the date and time manually:
sudo date -s 'DATE'
For example:
sudo date -s '2021-01-04 13:04:00'
The date is not required, you can also use:
sudo date -s '13:04: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 (link to my favorites), so it should work even if you are not using Raspberry Pi OS.

However, it might not work if your system has time synchronization enabled (NTP). You need to disable it first with:
sudo timedatectl set-ntp false
Once disabled, do the previous command again, and it should keep your entry as the current date/time.

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

Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember and a free downloadable cheat sheet so you can have the commands at your fingertips.

🖋 Love Raspberry Pi & writing?
Combine your passions and get paid. Write for RaspberryTips!

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 is working 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 Raspberry Pi OS to manage it.
For example, even if your Raspberry Pi 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.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

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

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!

Video

If you want to see those tips in action, you can watch this video on my YouTube channel:

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

Whenever you’re ready, here are other ways I can help you:

The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts

One Comment

  1. Yey, finally some one that can explain how to manually set time in rpi in 2021.
    It works!

Comments are closed.