Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
The toString() method of ZonedDateTime uses that of LocalDateTime, which in turn uses that of LocalTime. If we look at the source of OpenJDK, at least, we see the following method comment on toStr...
#1: Initial revision
The `toString()` method of `ZonedDateTime` uses that of `LocalDateTime`, which in turn uses that of `LocalTime`.
If we look at the [source](https://github.com/keerath/openjdk-8-source/blob/master/jdk/src/share/classes/java/time/LocalTime.java) of OpenJDK, at least, we see the following method comment on `toString`:
> The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.
"12:00" is understood (implied) to be a time; "12" on it's own is not.
We see in the code that when the seconds _and_ nanoseconds are 0, they will not be added to the String:
buf.append(hourValue < 10 ? "0" : "").append(hourValue)
.append(minuteValue < 10 ? ":0" : ":").append(minuteValue);
if (secondValue > 0 || nanoValue > 0) {
....
}
So, in short, it's on purpose. It's a feature, or at least intended to be one.
