備忘メモ。
Linuxのdateコマンドで和暦を表示する。
CentOS7のdateコマンド(GNU date)で確認。確認したバージョンは8.22。
なお、ubuntu18.10でも表示を確認。Macは西暦のみで和暦は出てこなかった。
要約:
dateコマンドに「+%Ec」「+%EC」「+%Ex」「+%EX」「+%Ey」「+%EY」を指定すると、和暦に関する情報が返ってくる。
詳しくは、下記「余談1:」を参照。
和暦を表示するには、localeは「LC_TIME="ja_JP.UTF-8"」が設定されている必要がある。あと、当然日本語フォントはいる。
余談1:
Eオプションはmanには載ってませんでした。
info dateで確認したら、以下のような説明がありました。
An optional modifier can follow the optional flag and width
specification. The modifiers are:
'E'
Use the locale's alternate representation for date and time. This
modifier applies to the '%c', '%C', '%x', '%X', '%y' and '%Y'
conversion specifiers. In a Japanese locale, for example, '%Ex'
might yield a date format based on the Japanese Emperors' reigns.
「Japanese Emperors' reigns」が元号(天皇の暦)と訳すのでしょうかね。