@adgjmptw39

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Java 和暦変換

Q&A

Closed

Javaで和暦変換を試しました。R〇年〇月〇日を表示させたいと思い
以下を記述しましたが令和〇年〇月〇日と表示されてしまいます。
Gの個数を変えることで表示が切り替わる認識でいました。
お手数をおかけしますが、ご教示をお願いします。

public class Test2 {
public static void main (String[] args) throws ParseException{
 Date date = new Date();
  //ロケールを指定してCalendarインスタンスを取得
Locale locale = new Locale("ja", "JP", "JP");
DateFormat format
= new SimpleDateFormat("Gyyyy年 MM月 dd日", locale);
DateFormat format1
= new SimpleDateFormat("GGyyyy年 MM月 dd日", locale);
DateFormat format2
= new SimpleDateFormat("GGGyyyy年 MM月 dd日", locale);
DateFormat format3
= new SimpleDateFormat("GGGGyyyy年 MM月 dd日", locale);
System.out.println(format.format(date));
System.out.println(format1.format(date));
System.out.println(format2.format(date));
System.out.println(format3.format(date));
}
}

結果
令和5年 06月 10日
令和5年 06月 10日
令和5年 06月 10日
令和5年 06月 10日

0 likes

1Answer

Comments

  1. @adgjmptw39

    Questioner

    ありがとうございます。Javaのバージョンにより異なるのですね。
    理解しました。

  2. タイトルの「返還」は「変換」に直してくださいね

Your answer might help someone💌