LoginSignup
0
1

コマンドでWindowsとLinuxのタイムゾーンを設定する

Last updated at Posted at 2023-12-10

本ブログは、オラクル・クラウドの個人シリーズ・ブログの1つです。

検証したOS
Windows 10, 11
Windows Server 2019,2022
Oracle Linux 7,8,9
Ubuntu 22

Windowsでの設定

コマンドプロンプトでの設定

※、タイムゾーンの確認は、管理者権限は不要ですが、変更する場合は管理者権限が必要です。

現在のタイムゾーンを確認する:tzutil /g
すべてのタイムゾーンをリストする:tzutil /l

C:\Windows\system32> tzutil /g
UTC
C:\Windows\system32> tzutil /l
......

日本標準時(JST)を設定する:tzutil /s <タイムゾーン名>

C:\Windows\system32>tzutil /s "Tokyo Standard Time"
C:\Windows\system32>tzutil /g
Tokyo Standard Time
C:\Windows\system32>

PowerShellでの設定

現在のタイムゾーンを確認する:Get-TimeZone

PS C:\Windows\system32> Get-TimeZone


Id                         : UTC
DisplayName                : (UTC) Coordinated Universal Time
StandardName               : Coordinated Universal Time
DaylightName               : Coordinated Universal Time
BaseUtcOffset              : 00:00:00
SupportsDaylightSavingTime : False

すべてのタイムゾーンをリストする:

Get-TimeZone -ListAvailable

日本標準時(JST)を設定する:Set-TimeZone -Id <タイムゾーン名>

Set-TimeZone -Id "Tokyo Standard Time"

Linuxでの設定

現在のタイムゾーンを確認する:

[opc@linux8 ~]$ timedatectl
               Local time: Thu 2022-07-28 03:09:35 UTC
           Universal time: Thu 2022-07-28 03:09:35 UTC
                 RTC time: Thu 2022-07-28 03:09:36
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[opc@linux8 ~]$

日本のタイムゾーンをリストする:

[opc@linux8 ~]$ timedatectl list-timezones | grep Tokyo
Asia/Tokyo
[opc@linux8 ~]$

日本標準時(JST)を設定する:(root権限は必要)

[opc@linux8 ~]$ sudo timedatectl set-timezone Asia/Tokyo
[opc@linux8 ~]$ timedatectl | grep zone
                Time zone: Asia/Tokyo (JST, +0900)
[opc@linux8 ~]$

付録 - 初期化スクリプト

クラウド上でVMを作成する際に、上記のコマンドをcloud-initスクリプトに配置すると、インスタンスの起動後にタイムゾーンが自動に設定されます。

日本標準時(JST)を設定する例:

Windows Server

#ps1_sysnative
Set-TimeZone -Id "Tokyo Standard Time"

Oracle Linux, Ubuntu

#!/bin/bash
timedatectl set-timezone Asia/Tokyo

関連記事
オラクル・クラウド関連の個人ブログ

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