Localized date format in Java

前端 未结 6 1184
夕颜
夕颜 2020-12-11 21:08

I have a timestamp in millis and want to format it indicating day, month, year and the hour with minutes precission.

I know I can specify the format like this:

6条回答
  •  攒了一身酷
    2020-12-11 21:20

    You can use method getDateTimeInstance, of DateFormat. Here the getDateTimeInstance method takes 3 arguments

    1. the style of Date field
    2. the style of time field
    3. the Locale using which pattern is auto extracted

      DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
      System.out.println(DATE_FORMAT.format(d));
      DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.FRENCH);
      System.out.println(DATE_FORMAT.format(d));
      

提交回复
热议问题