285

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?

1
  • Or easily echo UTC > /etc/timezone
    – SdSaati
    Dec 7, 2021 at 16:43

10 Answers 10

374

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.

13
  • 1
    Not a fan of +1 comments, but am putting one here since this worked for me in the best way. I was wanting a single one-line command line tool to change the timezone, rather than wanting to launch some whole either menu or gui program (I don't know what tzdata does, how it works, but I don't need to with this one line command). Thanks!
    – Phil Ryan
    Jun 1, 2015 at 23:21
  • works like a charm ;)
    – user332660
    Feb 24, 2016 at 10:01
  • Interestingly, it is doing something a little different than tzdata. I had an issue with Java time being different than the system time after applying a patch. Tzdata didn't work to fix the issue, but this did. Mar 23, 2016 at 15:54
  • 1
    this didn't work for me; however the dpkg-reconfigure did the trick. Apr 10, 2016 at 11:39
  • 14.04.4 ubuntu server Apr 10, 2016 at 11:44
58

As root you have to execute:

dpkg-reconfigure tzdata

A menu based tool should be started that allows you to change the timezone.

1
  • This also works on an install where timedatectl is not available (such as in some Docker containers). Nov 30, 2023 at 9:49
40

The following also work. For GMT:

ln -sf /usr/share/zoneinfo/GMT /etc/localtime

For EST:

ln -sf /usr/share/zoneinfo/EST /etc/localtime
4
  • 10
    I think it would be better to link one of the city files rather than GMT or EST, as then they will keep track of daylight savings time, whereas linking (e.g.) GMT will not change the system time to reflect when daylight savings is in effect in your city. e.g.: ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime Jun 8, 2015 at 9:19
  • 1
    this is the best Oct 17, 2018 at 12:48
  • 3
    I would caution against this. If something or someone accidentally overwrites /etc/localtime you have just lost your zoneinfo file. It's better to just copy the zoneinfo file over the /etc/localtime file.
    – J Roysdon
    May 4, 2020 at 19:33
  • 2
    On docker images 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.
    – cytsunny
    Oct 12, 2020 at 5:24
28

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! , :-)

7

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)

6

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.

6
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.

1
  • This actually worked for me. I think there's some bug with Docker, ansible (?). Both timedatectl and dpkg-reconfigure tzdata failed for me. After I copied, the time zone changed from EST to PDT.
    – Sun
    Jun 12, 2018 at 15:25
2

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.

0

As root you have to execute:

ln -fs /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && dpkg-reconfigure --frontend noninteractive tzdata

2
  • Please explain at least how this command works to change the timezone.
    – Parto
    Mar 19, 2019 at 17:15
  • I get > tzdata is not installed
    – Nam G VU
    Aug 2, 2020 at 10:32
0

This worked for me on GCP Ubuntu 14 via SSH

  1. sudo su
  2. cp /usr/share/zoneinfo/Asia/Singapore /etc/localtime
  3. Restart the server
  4. Done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .