How to change time-zone settings from the command line

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?

Asked By: manyxcxi

||

As root you have to execute:

dpkg-reconfigure tzdata

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

Answered By: maxschlepzig

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.

The following also work. For GMT:

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

For EST:

ln -sf /usr/share/zoneinfo/EST /etc/localtime
Answered By: pm_labs

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)

Answered By: chasapis.christos

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.

Answered By: Jossef Harush Kadouri

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! , 🙂

Answered By: Dimitrios
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.

Answered By: J Roysdon

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.

Answered By: Tom Hale

As root you have to execute:

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

Answered By: Stefan Sebastian

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
Answered By: Vignesh Chinnaiyan
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.