fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.DateFormat;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Calendar cal = Calendar.getInstance(new Locale("ja", "JP","JP"));
  14. DateFormat dtform = DateFormat.getDateInstance(
  15. DateFormat.FULL,new Locale("ja","JP","JP"));
  16. cal.setTime(new Date());
  17. String[] era = { " ", "明治","大正","昭和","平成","令和"};
  18. String eraName = era [cal.get(Calendar.ERA)];
  19. String formatted =dtform.format(new Date());
  20. System.out.println(formatted);
  21. }
  22. }
Success #stdin #stdout 0.19s 52808KB
stdin
Standard input is empty
stdout
令和5年1月31日