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