How to change time-zone settings from the command line

424,576

Solution 1

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.

Solution 2

As root you have to execute:

dpkg-reconfigure tzdata

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

Solution 3

The following also work. For GMT:

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

For EST:

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

Solution 4

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

Solution 5

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)

Share:
424,576

Related videos on Youtube

manyxcxi
Author by

manyxcxi

Just a dude.

Updated on September 17, 2022

Comments

  • manyxcxi
    manyxcxi almost 2 years

    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?

    • Admin
      Admin over 2 years
      Or easily echo UTC > /etc/timezone
  • Phil Ryan
    Phil Ryan about 9 years
    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!
  • Asfand Qazi
    Asfand Qazi about 9 years
    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
  • user332660
    user332660 over 8 years
    works like a charm ;)
  • Daniel Bower
    Daniel Bower over 8 years
    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.
  • 김석용
    김석용 about 8 years
    this didn't work for me; however the dpkg-reconfigure did the trick.
  • 김석용
    김석용 about 8 years
    14.04.4 ubuntu server
  • 김석용
    김석용 about 8 years
    Not only did the timedatectl report anything or give wrong status, the timezone was still wrong in date commands run from the shell; the dpkg-reconfigure tzdata and switching to UTC was instantaneous - even the time on zsh prompt jumped to another timezone
  • Jossef Harush Kadouri
    Jossef Harush Kadouri about 8 years
    @AnttiHaapala, thanks for sharing :) i'll check that. Any change you had [NTP / VM Hypervisor tools] race conditioned your command ?
  • 김석용
    김석용 about 8 years
    I don't think so.
  • code_dredd
    code_dredd about 6 years
    A quick note that this command is meant for systemd-based installations. If your system is an older version, then you may need to rely on tzdata instead.
  • Sun
    Sun about 6 years
    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.
  • tanius
    tanius about 6 years
    Note, this timedatectl solution persists after a reboot. No need for any additional steps to make it reboot safe!
  • Offboard
    Offboard almost 6 years
    Perfect, I use timedatectl set-timezone America/Maceio it's works.
  • Hasan Tıngır
    Hasan Tıngır over 5 years
    this is the best
  • Martin Thoma
    Martin Thoma over 5 years
    You might want to mention tzselect to find the desired timezone string.
  • Parto
    Parto over 5 years
    Please explain at least how this command works to change the timezone.
  • J Roysdon
    J Roysdon about 4 years
    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.
  • Nam G VU
    Nam G VU almost 4 years
    I get > tzdata is not installed
  • cytsunny
    cytsunny over 3 years
    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.