Locale locale = Locale.JAPAN;
LocalDateTime now = LocalDateTime.now();
Output program
Format with ofLocalizedDateTime.
System.out.println(
now.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withLocale(locale))
);
System.out.println(
now.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).withLocale(locale))
);
System.out.println(
now.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(locale))
);
System.out.println(
now.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(locale))
);
Execution result (from top, FULL, LONG, MEDIUM, SHORT)
java.time.DateTimeException: Unable to extract ZoneId from temporal 2019-07-01T07:58:21.538531
java.time.DateTimeException: Unable to extract ZoneId from temporal 2019-07-01T07:58:21.538531
2019/07/01 7:59:30
2019/07/01 7:59
Execution result (from top, FULL, LONG, MEDIUM, SHORT)
java.time.DateTimeException: Unable to extract ZoneId from temporal 2019-07-01T07:58:21.538531
java.time.DateTimeException: Unable to extract ZoneId from temporal 2019-07-01T07:58:21.538531
Jul 1, 2019, 7:57:26 AM
7/1/19, 7:57 AM
Recommended Posts