<Java>和暦で日付を表示

import java.util.Scanner;
import java.util.Locale;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.chrono.JapaneseDate;
import java.time.chrono.JapaneseChronology;

public class Main {
    public static void main(String[] args) {
        
        var locale = new Locale("ja", "JP");
        
        var date      = JapaneseDate.now();
        var formatter = DateTimeFormatter
                            .ofPattern("GGGGy年M月d日", locale);
        var text      = formatter.format(date);
        
        System.out.println(text);
        
        var date2      = LocalDate.now();
        var formatter2 = DateTimeFormatter
                            .ofPattern("GGGGy年M月d日", locale)
                            .withChronology(
                                JapaneseChronology.INSTANCE);
        var text2      = formatter2.format(date2);
        
        System.out.println(text2);
    }
}
令和2年10月12日
令和2年10月12日