In Java 17, a new date-time formatting pattern is indeed introduced, i.e. the pattern letter B, which is used to represent time periods of day, such as morning or afternoon. This mode defines the time period of the day according to the Unicode standard CLDR (Common Locale Data Repository). It can output time period identification such as "morning", "afternoon", "night" and other time periods.
package .java17; import ; import ; import ; /** * Date cycle formatting * * Chinese environment: jvm parameter-=GBK must be specified, otherwise there will be Chinese garbled code */ public class DateFormatDemo { public static void main(String[] args) { // Set up a localized environment (); // (); DateTimeFormatter dtf = ("h:mm B"); (((8, 0))); // morning (((13, 0))); // afternoon (((20, 0))); // night (((23, 0))); // night (((0, 0))); // Midnight } }
In English locale, set()
, the operation results are as follows:
8:00 in the morning
1:00 in the afternoon
8:00 in the evening
11:00 at night
12:00 midnight
In the Chinese language environment, set()
, the operation results are as follows:
8:00 am
1:00 pm
8:00 at night
11:00 at night
12:00 Midnight
It can be seen that our evening includes both evening and night in the United States.
This is the article about Java 17 date cycle formatting processing solution. For more related Java date cycle formatting content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!