Distinguishing between java Formatting Patterns: HH:mm, hh:mm, and kk:mm
The SimpleDateFormat class in Java provides various format patterns to display dates and times. While the HH:mm, hh:mm, and kk:mm patterns may seem similar, there are notable differences in their representations.
Consider the following Java code snippet:
SimpleDateFormat broken = new SimpleDateFormat("kk:mm:ss"); broken.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); SimpleDateFormat working = new SimpleDateFormat("HH:mm:ss"); working.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); SimpleDateFormat working2 = new SimpleDateFormat("hh:mm:ss"); working.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); System.out.println(broken.format(epoch)); System.out.println(working.format(epoch)); System.out.println(working2.format(epoch));
The output of the provided code is:
24:00:00 00:00:00 05:30:00
Let's break down the differences between these patterns:
Therefore, understanding the nuances of these formatting patterns is crucial for accurately representing dates and times in Java.
The above is the detailed content of What are the differences between HH:mm, hh:mm, and kk:mm in Java's SimpleDateFormat?. For more information, please follow other related articles on the PHP Chinese website!