🙆
タイムゾーンの設定
タイムゾーン
コンピュータなどの機器内部の時刻をどの地域の標準時で運用するかを定めた設定項目のこと。
タイムゾーンの情報
タイムゾーンの情報は/usr/share/zoneinfo配下にバイナリファイルとして保存されている。
[ec2-user@sandbox ~]$ ls /usr/share/zoneinfo
Africa Canada GB Indian Mexico ROK iso3166.tab
America Chile GB-Eire Iran NZ Singapore leapseconds
Antarctica Cuba GMT Israel NZ-CHAT Turkey posix
Arctic EET GMT+0 Jamaica Navajo UCT posixrules
Asia EST GMT-0 Japan PRC US right
Atlantic EST5EDT GMT0 Kwajalein PST8PDT UTC tzdata.zi
Australia Egypt Greenwich Libya Pacific Universal zone.tab
Brazil Eire HST MET Poland W-SU zone1970.tab
CET Etc Hongkong MST Portugal WET
CST6CDT Europe Iceland MST7MDT ROC Zulu
タイムゾーンの設定
タイムゾーン(東京)を設定するには、
- /usr/share/zoneinfo/Asia/Tokyoを/etc/localtimeにコピー
- /usr/share/zoneinfo/Asia/Tokyoを/etc/localtimeにシンボリックリンクを作成する
- 環境変数TZに設定する
の3つ方法がある。
※TZの設定は/etc/localtimeよりも優先される。
# ①の方法
[ec2-user@sandbox ~]$ date
2021年 5月 4日 火曜日 01:30:36 UTC
[ec2-user@sandbox ~]$ sudo cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
[ec2-user@sandbox ~]$ date
2021年 5月 4日 火曜日 10:31:25 JST
# ②の方法
[ec2-user@sandbox ~]$ sudo rm -i /etc/localtime
rm: 通常ファイル `/etc/localtime' を削除しますか? y
[ec2-user@sandbox ~]$ sudo ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime
[ec2-user@sandbox ~]$ date
2021年 5月 4日 火曜日 01:35:53 UTC
# ③の方法
[ec2-user@sandbox ~]$ export TZ=Asia/Tokyo
[ec2-user@sandbox ~]$ date
2021年 5月 4日 火曜日 10:36:37 JST
タイムゾーンの一覧確認
tzselectコマンドを利用すると、各地域の一覧から対話型によるタイムゾーンの設定値を確認することができる。
[ec2-user@sandbox ~]$ tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa
2) Americas
3) Antarctica
4) Asia
5) Atlantic Ocean
6) Australia
7) Europe
8) Indian Ocean
9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the time zone using the Posix TZ format.
#? 4
Please select a country whose clocks agree with yours.
1) Afghanistan 18) Israel 35) Palestine
2) Armenia 19) Japan 36) Philippines
3) Azerbaijan 20) Jordan 37) Qatar
4) Bahrain 21) Kazakhstan 38) Russia
5) Bangladesh 22) Korea (North) 39) Saudi Arabia
6) Bhutan 23) Korea (South) 40) Singapore
7) Brunei 24) Kuwait 41) Sri Lanka
8) Cambodia 25) Kyrgyzstan 42) Syria
9) China 26) Laos 43) Taiwan
10) Cyprus 27) Lebanon 44) Tajikistan
11) East Timor 28) Macau 45) Thailand
12) Georgia 29) Malaysia 46) Turkmenistan
13) Hong Kong 30) Mongolia 47) United Arab Emirates
14) India 31) Myanmar (Burma) 48) Uzbekistan
15) Indonesia 32) Nepal 49) Vietnam
16) Iran 33) Oman 50) Yemen
17) Iraq 34) Pakistan
#? 19
The following information has been given:
Japan
Therefore TZ='Asia/Tokyo' will be used.
Selected time is now: Tue May 4 10:40:23 JST 2021.
Universal Time is now: Tue May 4 01:40:23 UTC 2021.
Is the above information OK?
1) Yes
2) No
#? 1
You can make this change permanent for yourself by appending the line
TZ='Asia/Tokyo'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Tokyo
[ec2-user@sandbox ~]$
時刻、タイムゾーンの詳細情報を表示確認
timedatectlコマンドを実行することで、時刻やタイムゾーンの詳細情報を確認することができる。
[ec2-user@sandbox ~]$ timedatectl
Local time: 火 2021-05-04 11:16:38 JST
Universal time: 火 2021-05-04 02:16:38 UTC
RTC time: 火 2021-05-04 02:16:38
Time zone: Asia/Tokyo (JST, +0900)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
Discussion