How to set the time zone in Amazon EC2?

后端 未结 11 1395
迷失自我
迷失自我 2020-12-22 19:33

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

相关标签:
11条回答
  • 2020-12-22 19:53

    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

    0 讨论(0)
  • 2020-12-22 19:55

    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
    
    0 讨论(0)
  • 2020-12-22 19:58

    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
    
    0 讨论(0)
  • 2020-12-22 19:59

    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
    
    0 讨论(0)
  • 2020-12-22 19:59

    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
    
    0 讨论(0)
提交回复
热议问题