For most people, the Raspberry Pi operating system (whatever the one you use) will do this in the background, and it shouldn’t be an issue.
But in some cases, like if you are just getting started on Raspberry Pi or using it without an Internet connection, it can be an issue.
In this post, we’ll see how to fix any date & time issue 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 possible to set 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, whatever if you are using a Desktop environment or not, and if your Pi is connected to the Internet or not.
Why are date and time an issue on Raspberry Pi?
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
On a computer, you’ll rarely think about setting the date and time correctly.
You might configure it after the installation, and will probably forget about it for years.
But on Raspberry Pi, you might have an issue regularly, especially when using it without Internet access, or by 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 a 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.
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 Raspbian 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.
Set Date and Time on Raspberry Pi OS with Desktop
Grab your free PDF file with all the commands you need to know on Raspberry Pi!
If you are on Raspberry Pis OS, the date and time configuration should be pretty easy if you have any 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 a bunch of information.
One of them is your location.
Your Pi doesn’t just ask for it out of curiosity, but to set the time zone according to your answer.
Once the timezone 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.
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 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.
Before going further, if you are a bit lost on Raspberry Pi OS Desktop, and need help to get 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. I will also guide you to complete your 5 first projects on Raspberry Pi.
You can find more details about this on this page.
If you have any comment, suggestion or just want to chat with us about this tutorial,
you can post your messages in the community on Patreon. See you there!
Set Date and Time in the command line
If you are using Raspberry Pi OS Lite, or connected via SSH, you don’t have access to these tools. No worry, there are similar alternatives while in the command line.
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:
- 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:
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'
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 doubt.
Use the command “date” to check if it changed it as expected:
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.
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 an 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 details about this, but I have a dedicated guide about NTP that you should definitely read if you are interested.