How do I get localized date pattern string?

前端 未结 10 2315
死守一世寂寞
死守一世寂寞 2020-11-28 05:31

It is quite easy to format and parse Java Date (or Calendar) classes using instance of DateFormat, i.e. I could format current date into short localize date like this:

10条回答
  •  星月不相逢
    2020-11-28 05:53

    For SimpleDateFormat, You call toLocalizedPattern()

    EDIT:

    For Java 8 users:

    The Java 8 Date Time API is similar to Joda-time. To gain a localized pattern we can use class DateTimeFormatter

    DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);

    Note that when you call toString() on LocalDate, you will get date in format ISO-8601

    Note that Date Time API in Java 8 is inspired by Joda Time and most solution can be based on questions related to time.

提交回复
热议问题