LoginSignup
0
0

More than 5 years have passed since last update.

# Get-Date -format yyyyMMdd したら年が2桁で返ってきた

Posted at

若干トラブルシュートしたので備忘録。

Get-Date -Format と指定するとカスタム書式で日時が取得できる。

Get-Date -Format "yyyyMMdd"

#想定される値 -> [String]20170131
#取得してきた値 -> [String]290131

年が2桁・・・?

平成が取れてきちゃった・・・。

スクリプトが動いていた環境ではGet-Dateしたときはちゃんと西暦が取れていたので、
おかしいなぁと思って調べてみたら、端末のシステムクロックをそのまま使っているらしい。

解決策

Windows7の場合

[日付と時刻の変更]
->[カレンダー設定の変更]
->[追加の設定]
->[日付]タブから、「カレンダーの種類」-> 西暦(日本語)に変更

Get-Date -Format "yyyyMMdd"

#取得値 -> [String]20170131

ちゃんと西暦が取得できました。
なぜ端末が和暦設定になっていたのかは不明だけど、Get-Dateでyyyyやると西暦で取得してくるって信じて疑わなかったので参りました。

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