If you’ve ever typed
date into your Ubuntu Server and seen a different time or timezone appear than you expected, then it probably means that this tutorial is for you.
Check current timezone
Start by checking what data is returned using the following command:
In my case, I wanted to make sure my server’s time was in UTC, London. However, it was reported as being in Berlin.
$ timedatectl Local time: Fri 2020-03-20 11:08:41 CET Universal time: Fri 2020-03-20 10:08:41 UTC RTC time: Fri 2020-03-20 10:08:42 Time zone: Europe/Berlin (CET, +0100) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
Ubuntu uses symbolic files to link configurations for timezones.
So if you type
ls -l /etc/localtime, you will see why this configuration has been mapped:
$ ls -l /etc/localtime lrwxrwxrwx 1 .. .. 33 Jul 14 2019 /etc/localtime -> /usr/share/zoneinfo/Europe/Berlin
Find our new timezone
We can get a list of all the available timezones by typing
I already know that I want
London, so let’s filter that list for the value first:
$ timedatectl list-timezones | grep -i "london" Europe/London
Set the new timezone
Next, we need to remove the symbolic link to the
localtime file and then relink it.
sudo unlink /etc/localtime
Now we can relink the file:
sudo ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
At this stage, everything is set up, so let’s see it working:
$ timedatectl Local time: Fri 2020-03-20 10:10:24 GMT Universal time: Fri 2020-03-20 10:10:24 UTC RTC time: Fri 2020-03-20 10:10:25 Time zone: Europe/London (GMT, +0000) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
Reload all scripts and servers
It’s now important to reload
Apache2 or any servers, or running scripts that had cached the date/time/timezone from before the change.
In my case, I will just kill all PHP scripts running and reload Apache2.
pkill php service apache2 restart