2021-06-27

Java 16 - Day Period Support Added to java.time Formats

A new formatter pattern, letter 'B', and its supporting method have been added to java.time.format.DateTimeFormatter/DateTimeFormatterBuilder classes. The pattern and method translate day periods defined in Unicode Consortium's CLDR (https://unicode.org/reports/tr35/tr35-dates.html#dayPeriods). Applications can now express periods in a day, such as "in the morning" or "at night", not just am/pm. The following example demonstrates translating the day periods:

DateTimeFormatter.ofPattern("B").format(LocalTime.now()) 
This example produces day period text depending on the time of the day and locale.

No comments:

Post a Comment