LoginSignup
5
5

More than 3 years have passed since last update.

サーバの時間を日本の時間に設定する方法

Last updated at Posted at 2020-06-30

サーバの時間が世界の標準時間だった、ときのこと

何も設定していなければこうなるはず、だけど日本人で東京在住なので東京時間がいい。

$ date
Fri Jun 12 04:32:25 UTC 2020

CentOS7の場合

  • 環境 : CentOS Linux release 7.8.2003 (Core)
# localtimeはUTCにリンクされている
$ ls -la /etc/localtime
lrwxrwxrwx. 1 root root 25 Feb 29 12:11 /etc/localtime -> ../usr/share/zoneinfo/UTC

# ちょっと日本を探してみたら「Asia」「Japan」があった
$ ls -la /usr/share/zoneinfo/ | grep -e Asia -e Japan
drwxr-xr-x.  2 root root   4096 Feb 29 12:06 Asia
-rw-r--r--.  2 root root    292 Sep 26  2019 Japan

# `Asia/Tokyo`が`Japan`にリンクされているわけではないらしい
$ ls -la /usr/share/zoneinfo/Asia/ | grep Tokyo
-rw-r--r--.  2 root root  292 Sep 26  2019 Tokyo

今だけ日本の時間にする方法

参考 : 【Linux】タイムゾーン(Timezone)の変更 - Qiita

# Tokyoにシンボリックリンクを上書きではる
$ ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
$  ls -la /etc/localtime
lrwxrwxrwx. 1 root root 30 Jun 15 10:45 /etc/localtime -> /usr/share/zoneinfo/Asia/Tokyo

$ date
Mon Jun 15 10:45:55 JST 2020

ずっと日本の時間にする方法

参考 : 【 timedatectl 】コマンド――時刻を表示/設定する:Linux基本コマンドTips(312) - @IT

$ timedatectl
      Local time: Tue 2020-06-30 06:20:07 UTC
  Universal time: Tue 2020-06-30 06:20:07 UTC
        RTC time: Tue 2020-06-30 06:20:07
       Time zone: UTC (UTC, +0000)
...省略...

# 日本っぽいのを探すと「Asia/Tokyo」があった
$ timedatectl list-timezones | grep -i -e japan -e tokyo
Asia/Tokyo

# タイムゾーンを「Asia/Tokyo」に設定する
$ sudo timedatectl set-timezone Asia/Tokyo

$ timedatectl
      Local time: Tue 2020-06-30 15:21:18 JST
  Universal time: Tue 2020-06-30 06:21:18 UTC
        RTC time: Tue 2020-06-30 06:21:18
       Time zone: Asia/Tokyo (JST, +0900)
...省略...

$ date
Tue Jun 30 15:21:31 JST 2020
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5