LoginSignup
0
0

More than 3 years have passed since last update.

[Java]DateTimeFormatterのFormatStyle別出力

Last updated at Posted at 2019-06-30

ロケールを日本

        Locale locale = Locale.JAPAN;
        LocalDateTime now = LocalDateTime.now();

出力プログラム

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))
        );

実行結果(上から、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

ロケールをアメリカ

実行結果(上から、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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0