How to set the time zone in Amazon EC2?

Amazon Web-ServicesUbuntuAmazon Ec2

Amazon Web-Services Problem Overview


I want to change the time zone set in my Amazon EC2 instance running Ubuntu Linux to local time?

My Question

How to change the time zone in Amazon EC2?

Amazon Web-Services Solutions


Solution 1 - Amazon Web-Services

it should be no different than your desktop Ubuntu process. See here

  1. SSH to your EC2 server

  2. execute the following (to set timezone to Australia/Adelaide)

     $ echo "Australia/Adelaide" | sudo tee /etc/timezone
     Australia/Adelaide
     $ sudo dpkg-reconfigure --frontend noninteractive tzdata
     
     Current default time zone: 'Australia/Adelaide'
     Local time is now:      Sat May  8 21:19:24 CST 2010.
     Universal Time is now:  Sat May  8 11:49:24 UTC 2010.
    

Update

You can use tzselect utility to browse through. See here: http://manpages.ubuntu.com/manpages/precise/man1/tzselect.1.html

It's an interactive software. My Ubuntu (11.10) has it.

You could also refer this Wikipedia article

Brazil

Brazil/Acre
Brazil/DeNoronha
Brazil/East
Brazil/West

Solution 2 - Amazon Web-Services

Another way of changing the time (This was done on an Amazon EC2 Linux instance)

Remove your localtime file

sudo rm /etc/localtime

Change Directory to ZoneInfo

cd /usr/share/zoneinfo

This folder contains all of the timezone information. You then just need to softlink to the appropriate zone.

Create a softlink to /etc/localtime

sudo ln -s /usr/share/zoneinfo/GB /etc/localtime

That will change your server timezone to GB

Solution 3 - Amazon Web-Services

Check your current time zone by

$ date

To change it, run

$ sudo dpkg-reconfigure tzdata

This will show list of geographical areas. Select to narrow down available time zones. Next select city/timezone. And you have changed system to new timezone.

Solution 4 - Amazon Web-Services

Information is available in aws documentation for changing the time zone in ec2 machine .Please find below the details :

Changing the Time Zone

Amazon Linux instances are set to the UTC (Coordinated Universal Time) time zone by default, but you may wish to change the time on an instance to the local time or to another time zone in your network.

To change the time zone on an instance

1.Identify the time zone to use on the instance. The /usr/share/zoneinfo directory contains a hierarchy of time zone data files. Browse the directory structure at that location to find a file for your time zone.

[ec2-user ~]$ ls /usr/share/zoneinfo
Africa      Chile    GB         Indian       Mideast   posixrules  US
America     CST6CDT  GB-Eire    Iran         MST       PRC         UTC
Antarctica  Cuba     GMT        iso3166.tab  MST7MDT   PST8PDT     WET
Arctic      EET      GMT0       Israel       Navajo    right       W-   SU
...

Some of the entries at this location are directories (such as America), and these directories contain time zone files for specific cities. Find your city (or a city in your time zone) to use for the instance. In this example, you can use the time zone file for Los Angeles, /usr/share/zoneinfo/America/Los_Angeles.

2.Update the /etc/sysconfig/clock file with the new time zone.

a.Open the /etc/sysconfig/clock file with your favorite text editor (such as vim or nano). You need to use sudo with your editor command because /etc/sysconfig/clock is owned by root.

b.Locate the ZONE entry, and change it to the time zone file (omitting the /usr/share/zoneinfo section of the path). For example, to change to the Los Angeles time zone, change the ZONE entry to the following.

ZONE="America/Los_Angeles"

c.Save the file and exit the text editor.

3.Create a symbolic link between /etc/localtime and your time zone file so that the instance finds the time zone file when it references local time information.

[ec2-user ~]$ sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

4.Reboot the system to pick up the new time zone information in all services and applications.

[ec2-user ~]$ sudo reboot

Solution 5 - Amazon Web-Services

None of the above steps worked for me, so thought of writing this new answer here

# Delete any existing localtime link
sudo rm /etc/localtime
# Update time clock file with ZONE property
sudo vi /etc/sysconfig/clock
#Update the ZONE property to what you want say
ZONE="America/Los_Angeles"
sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
sudo reboot

Solution 6 - Amazon Web-Services

UPDATED ANSWER FOR UBUNTU 16.04:

Do:

sudo timedatectl set-timezone America/New_York

to update your timezone.

To list down all the available timezones you can do:

timedatectl list-timezones

Solution 7 - Amazon Web-Services

from RHEL 7 admin guide

Seems this might be the command on REDHAT7

timedatectl set-timezone "Europe/Stockholm"

To get all available timezones type:

timedatectl list-timezone

for more informations use

man timedatectrl

Solution 8 - Amazon Web-Services

Locate your timezone in the directory /usr/share/zoneinfo/.

E.g. To change timezone for Toronto /usr/share/zoneinfo/America/Toronto

Symlink your timezone to /etc/localtime e.g. for Toronto:

sudo ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime

Reboot to finish

reboot

Solution 9 - Amazon Web-Services

For Red Hat or CentOS:

Check the time:

timedatectl status

List all available timezones:

timedatectl list-timezones

Set up your timezone:

sudo timedatectl set-timezone Europe/Paris

Solution 10 - Amazon Web-Services

Solution 11 - Amazon Web-Services

NOTE: This refers to a linux box (debian in my instance) should be used under your AWS launch configurations "User Data".

If you're planning to set the TIMEZONE on instance boot use below (works like a charm) use you're own Country/City instead of "Australia/Sydney".

#!/bin/bash

/bin/rm -f /etc/localtime; /bin/ln -s /usr/share/zoneinfo/Australia/Sydney /etc/localtime

Solution 12 - Amazon Web-Services

When you create a new EC2 instance and select "Amazon Linux 2 AMI (HVM)" as Amazon Machine Image (AMI), you can insert these lines in the "User Data" section. Based on which region you are in, change the second line with the timezone that works for you. I am in Central European Time (CET). Bear in mind that this bootstrap code is executed as root and only once when the instance is created.

#!/bin/bash
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/CET /etc/localtime

If you want to see all the other timezones available, ssh to one instance and run:

ls /usr/share/zoneinfo

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGaurav AgarwalView Question on Stackoverflow
Solution 1 - Amazon Web-ServicesNishantView Answer on Stackoverflow
Solution 2 - Amazon Web-ServicesajtrichardsView Answer on Stackoverflow
Solution 3 - Amazon Web-Servicessanjeev barnwalView Answer on Stackoverflow
Solution 4 - Amazon Web-ServicesVarunView Answer on Stackoverflow
Solution 5 - Amazon Web-ServicesHemantView Answer on Stackoverflow
Solution 6 - Amazon Web-ServicesAakash MalhotraView Answer on Stackoverflow
Solution 7 - Amazon Web-ServicesTheRuegerView Answer on Stackoverflow
Solution 8 - Amazon Web-ServicesAnthony AwuleyView Answer on Stackoverflow
Solution 9 - Amazon Web-ServicesEnesZView Answer on Stackoverflow
Solution 10 - Amazon Web-ServicesRohit ParteView Answer on Stackoverflow
Solution 11 - Amazon Web-ServicesRodrigo RubioView Answer on Stackoverflow
Solution 12 - Amazon Web-ServicesOlivier CView Answer on Stackoverflow