如何在Amazon EC2中设置时区?

时间:2023-01-26 12:47:15

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

我想将运行Ubuntu Linux的Amazon EC2实例中设置的时区更改为本地时间?

My Question

我的问题

How to change the time zone in Amazon EC2?

如何更改Amazon EC2中的时区?

9 个解决方案

#1


73  

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

它应该与您的桌面Ubuntu进程没有什么不同。看这里

  1. SSH to your EC2 server
  2. SSH到您的EC2服务器
  3. 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

您可以使用tzselect实用程序进行浏览。请参见此处:http://manpages.ubuntu.com/manpages/precise/man1/tzselect.1.html

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

这是一个交互式软件。我的Ubuntu(11.10)有它。

You could also refer this Wikipedia article

您也可以参考这篇*文章

Brazil

巴西

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

#2


36  

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

另一种改变时间的方法(这是在Amazon EC2 Linux实例上完成的)

Remove your localtime file

删除您的本地时间文件

sudo rm /etc/localtime

Change Directory to ZoneInfo

将目录更改为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

创建/ etc / localtime的软链接

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

That will change your server timezone to GB

这会将您的服务器时区更改为GB

#3


9  

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.

这将显示地理区域列表。选择缩小可用时区。接下来选择城市/时区。并且您已将系统更改为新时区。

#4


8  

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

#5


8  

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

aws文档中提供了有关更改ec2机器中时区的信息。请在下面找到详细信息:

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.

默认情况下,Amazon Linux实例设置为UTC(协调世界时)时区,但您可能希望将实例上的时间更改为本地时间或网络中的其他时区。

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.

1.标识要在实例上使用的时区。 / usr / share / zoneinfo目录包含时区数据文件的层次结构。浏览该位置的目录结构以查找您所在时区的文件。

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

此位置的某些条目是目录(例如America),这些目录包含特定城市的时区文件。找到您要用于实例的城市(或您所在时区的城市)。在此示例中,您可以使用洛杉矶的时区文件,/ usr / share / zoneinfo / America / Los_Angeles。

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

2.使用新时区更新/ etc / sysconfig / clock文件。

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.

a。使用您喜欢的文本编辑器(例如vim或nano)打开/ etc / sysconfig / clock文件。您需要在编辑器命令中使用sudo,因为/ etc / sysconfig / clock由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.

b.Locate ZONE条目,并将其更改为时区文件(省略路径的/ usr / share / zoneinfo部分)。例如,要更改为洛杉矶时区,请将ZONE条目更改为以下内容。

ZONE="America/Los_Angeles"

c.Save the file and exit the text editor.

c。保存文件并退出文本编辑器。

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.

3.在/ etc / localtime和您的时区文件之间创建一个符号链接,以便实例在引用本地时间信息时查找时区文件。

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

4.重新启动系统以获取所有服务和应用程序中的新时区信息。

[ec2-user ~]$ sudo reboot

#6


3  

from RHEL 7 admin guide

来自RHEL 7管理员指南

Seems this might be the command on REDHAT7

似乎这可能是REDHAT7上的命令

timedatectl set-timezone "Europe/Stockholm"

To get all available timezones type:

要获取所有可用的时区类型:

timedatectl list-timezone

for more informations use

获取更多信息

man timedatectrl

#7


1  

UPDATED ANSWER FOR UBUNTU 16.04:

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

#8


0  

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

注意:这指的是应在您的AWS启动配置“用户数据”下使用linux框(我的实例中为debian)。

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

如果您打算在下面的实例启动时设置TIMEZONE(就像魅力一样),请使用您自己的国家/城市而不是“澳大利亚/悉尼”。

#!/bin/bash

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

#9


0  

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

在/ usr / share / zoneinfo /目录中找到您的时区

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

例如。更改多伦多/ usr / share / zoneinfo / America / Toronto的时区

symlink your timezone to /etc/localtime e.g for Toronto

将您的时区符号链接到/ etc / localtime,例如多伦多

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

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

Reboot to finish

重新启动完成

reboot

重启

#1


73  

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

它应该与您的桌面Ubuntu进程没有什么不同。看这里

  1. SSH to your EC2 server
  2. SSH到您的EC2服务器
  3. 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

您可以使用tzselect实用程序进行浏览。请参见此处:http://manpages.ubuntu.com/manpages/precise/man1/tzselect.1.html

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

这是一个交互式软件。我的Ubuntu(11.10)有它。

You could also refer this Wikipedia article

您也可以参考这篇*文章

Brazil

巴西

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

#2


36  

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

另一种改变时间的方法(这是在Amazon EC2 Linux实例上完成的)

Remove your localtime file

删除您的本地时间文件

sudo rm /etc/localtime

Change Directory to ZoneInfo

将目录更改为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

创建/ etc / localtime的软链接

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

That will change your server timezone to GB

这会将您的服务器时区更改为GB

#3


9  

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.

这将显示地理区域列表。选择缩小可用时区。接下来选择城市/时区。并且您已将系统更改为新时区。

#4


8  

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

#5


8  

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

aws文档中提供了有关更改ec2机器中时区的信息。请在下面找到详细信息:

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.

默认情况下,Amazon Linux实例设置为UTC(协调世界时)时区,但您可能希望将实例上的时间更改为本地时间或网络中的其他时区。

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.

1.标识要在实例上使用的时区。 / usr / share / zoneinfo目录包含时区数据文件的层次结构。浏览该位置的目录结构以查找您所在时区的文件。

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

此位置的某些条目是目录(例如America),这些目录包含特定城市的时区文件。找到您要用于实例的城市(或您所在时区的城市)。在此示例中,您可以使用洛杉矶的时区文件,/ usr / share / zoneinfo / America / Los_Angeles。

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

2.使用新时区更新/ etc / sysconfig / clock文件。

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.

a。使用您喜欢的文本编辑器(例如vim或nano)打开/ etc / sysconfig / clock文件。您需要在编辑器命令中使用sudo,因为/ etc / sysconfig / clock由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.

b.Locate ZONE条目,并将其更改为时区文件(省略路径的/ usr / share / zoneinfo部分)。例如,要更改为洛杉矶时区,请将ZONE条目更改为以下内容。

ZONE="America/Los_Angeles"

c.Save the file and exit the text editor.

c。保存文件并退出文本编辑器。

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.

3.在/ etc / localtime和您的时区文件之间创建一个符号链接,以便实例在引用本地时间信息时查找时区文件。

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

4.重新启动系统以获取所有服务和应用程序中的新时区信息。

[ec2-user ~]$ sudo reboot

#6


3  

from RHEL 7 admin guide

来自RHEL 7管理员指南

Seems this might be the command on REDHAT7

似乎这可能是REDHAT7上的命令

timedatectl set-timezone "Europe/Stockholm"

To get all available timezones type:

要获取所有可用的时区类型:

timedatectl list-timezone

for more informations use

获取更多信息

man timedatectrl

#7


1  

UPDATED ANSWER FOR UBUNTU 16.04:

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

#8


0  

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

注意:这指的是应在您的AWS启动配置“用户数据”下使用linux框(我的实例中为debian)。

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

如果您打算在下面的实例启动时设置TIMEZONE(就像魅力一样),请使用您自己的国家/城市而不是“澳大利亚/悉尼”。

#!/bin/bash

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

#9


0  

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

在/ usr / share / zoneinfo /目录中找到您的时区

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

例如。更改多伦多/ usr / share / zoneinfo / America / Toronto的时区

symlink your timezone to /etc/localtime e.g for Toronto

将您的时区符号链接到/ etc / localtime,例如多伦多

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

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

Reboot to finish

重新启动完成

reboot

重启