Quantcast
Channel: プログラミング
Viewing all articles
Browse latest Browse all 7890

【Linux】日時/タイムゾーン関連のコマンド - プログラム の超個人的なメモ

$
0
0

■ はじめに

日時/タイムゾーン関連のLinuxコマンドをメモ。

目次

【1】日時 - dateコマンド -
 1)確認
 2)変更
 3)日時あれこれ
【2】タイムゾーン - timedatectlコマンド -
 1)確認
 2)変更

 【1】日時 - dateコマンド -

 1)確認

# 現在の日時を表示
$ date
Mon Oct  7 22:49:12     2024# 現在の日時をUTCで表示
$ date -u
Mon Oct  7 13:48:22 UTC 2024##### -dオプション##### 24時間後の日時を表示
$ date -d tomorrow
Tue Oct  8 22:53:55     2024# 30日後の日付を表示
$ date "+%Y/%m/%d"-d"30 days"2024/11/06

https://qiita.com/setonao/items/85435d5f7c480425ba95

オプション

OptionsExplanationsMemo
-d指定したオプションで日時を取得
-uUTCを取得
+[format]指定した形式で日時を取得

2)変更

$ sudo date --set="2017-03-27 10:32:20"

3)日時あれこれ

[1] フォーマットを指定して出力

$ date +"%Y%m%d"20241007# フォーマットは + で始まる書式で指定
$ date "+%Y-%m-%d %H:%M:%S"
2024-10-07 22:50:47

[2] 指定した年月で末日を算出する

date +%Y%m%d -d"-1 days + 1 month $(date -d '-1days + 1 month <年>/<月>'/1 +%Y%m01)"

https://orebibou.com/ja/home/201606/20160617_002/

##### 2024年9月##### 末日
$ date +"%Y%m%d"-d"-1 days + 1 month 20240901"20240930##### 2024年10月##### 末日
$ date +"%Y%m%d"-d"-1 days + 1 month 20241001"20241031

 【2】タイムゾーン - timedatectlコマンド -

1)確認

timedatectl
timedatectl status

出力結果例

      Local time: 火 2017-02-07 23:24:27 JST
  Universal time: 火 2017-02-07 14:24:27 UTC
        RTC time: 火 2017-02-07 14:24:28
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

 2)変更

timedatectl set-timezone Asia/Tokyo
timedatectl set-timezone UTC

 補足 : タイムゾーンについて

* UTC (Universal Time Coordinated) : 協定世界時
* GMT (Greenwich Mean Time) : グリニッジ標準時

 参考文献

http://qiita.com/snaka/items/a291423d6ceac9f091a7

 関連記事

Amazon S3AWSCLI / aws s3 ls ~
https://dk521123.hatenablog.com/entry/2024/10/07/152215


Viewing all articles
Browse latest Browse all 7890

Trending Articles