I have a virtual machine that is set to PST that a couple of colleagues have in different time-zones.
If I wanted to change the time-zone to EST and GMT, what do I need to do?
Use timedatectl
sudo timedatectl set-timezone <timeszone>
Examples:
Timezone as EST
sudo timedatectl set-timezone EST
Timezone as UTC
sudo timedatectl set-timezone UTC
Listing all valid Timezones
timedatectl list-timezones
This command is perfect for automation scripts since it doesn't require any user interaction while compared to the other given answer based on dpkg-reconfigure tzdata
.
tzdata
does, how it works, but I don't need to with this one line command). Thanks!
Commented
Jun 1, 2015 at 23:21
dpkg-reconfigure
did the trick.
Commented
Apr 10, 2016 at 11:39
As root you have to execute:
dpkg-reconfigure tzdata
A menu based tool should be started that allows you to change the timezone.
timedatectl
is not available (such as in some Docker containers).
Commented
Nov 30, 2023 at 9:49
The following also work. For GMT:
ln -sf /usr/share/zoneinfo/GMT /etc/localtime
For EST:
ln -sf /usr/share/zoneinfo/EST /etc/localtime
ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
Commented
Jun 8, 2015 at 9:19
timedatectl
may not be installed out of the box, and it is really overkill to install a tools just to change time zone. This is the only answer that allow setting timezone with system command only. In this sense, I would say this is the best answer.
The most ease way especially to a server is to list timezones:
timedatectl list-timezones
And choose yours, for example:
timedatectl set-timezone Europe/Athens
Thats it! , :-)
Edit the timezone
file at the /etc
folder as:
Etc/GMT
You can use the next format:
Region "/" City
Example of /etc/timezone
:
Europe/Athens
or
Europe/Paris
Europe/London
You may experiment with the: dpkg-reconfigure tzdata
and check cat the timezone file.
You must reboot or start again a service (not the ntp service). I do not know which one. If somebody knows please share with us. (Tested on Ubuntu 15.10 the change is taken into account instantly)
To run one program with a different time zone setting, set the TZ
environment variable, e.g. run TZ=Pacific/Kiritimati date
to see what time it is on Christmas Island, or export TZ=Pacific/Kiritimati
to have the setting last for a shell session.
cp -p /usr/share/zoneinfo/US/Pacific /etc/localtime
I recommend AGAINST linking like mentioned by others. If some script accidentally over writes your /etc/localtime
file, then it overwrites your Pacific timezone file... and it's a bit of a pain to replace it.
Just copy the Pacific file over the localtime file with the command above.
I use the following script to ask the user which timezone to set, and then confirm it has indeed been set:
#!/bin/sh
sudo timedatectl set-timezone $(tzselect)
echo
echo timedatectl says:
timedatectl
I call it tz-set
.
As root you have to execute:
ln -fs /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && dpkg-reconfigure --frontend noninteractive tzdata
This worked for me on GCP Ubuntu 14 via SSH
sudo su
cp /usr/share/zoneinfo/Asia/Singapore /etc/localtime
echo UTC > /etc/timezone