Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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

77%
+5 −0
Q&A java.time.ZonedDateTime missing seconds in output

When printing a java.time.ZonedDateTime, it's missing the seconds in output, is it a bug or a feature? See my code: package tryNcry; import java.time.Instant; import java.time.ZoneId; import...

2 answers  ·  posted 10mo ago by watchmaker‭  ·  edited 10mo ago by watchmaker‭

Question java datetime
#4: Post edited by user avatar watchmaker‭ · 2025-11-16T21:15:05Z (10 months ago)
typo
  • When printing a `java.time.ZonedDateTime`, it's missing the seconds in output, is it a bug or a feature?
  • See my code:
  • ```java
  • package tryNcry;
  • import java.time.Instant;
  • import java.time.ZoneId;
  • import java.time.ZonedDateTime;
  • public class TestOfTime {
  • public static void main(String[] args) {
  • Instant naked = Instant.parse("2000-01-01T12:00:01Z");
  • System.out.println(naked);
  • ZonedDateTime withTimeZone = naked.atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(withTimeZone);
  • long toSeconds = withTimeZone.toEpochSecond();
  • ZonedDateTime recreated = Instant.ofEpochSecond(toSeconds).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • recreated = Instant.ofEpochSecond(toSeconds - 1).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • // output:
  • // 2000-01-01T12:00:01Z
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00+11:00[Australia/Melbourne]
  • }
  • }
  • ```
  • The last output skips the seconds. I would call it a (strange) feature if the minutes also would be skipped, but they are displayed.
  • What is it?
  • ----
  • Tanks for the answers, in short it is:
  • * it is documented, so it is a feature, not a bug
  • * you can easily circumvent that feature by specifying explicitly what format you want to have
  • When printing a `java.time.ZonedDateTime`, it's missing the seconds in output, is it a bug or a feature?
  • See my code:
  • ```java
  • package tryNcry;
  • import java.time.Instant;
  • import java.time.ZoneId;
  • import java.time.ZonedDateTime;
  • public class TestOfTime {
  • public static void main(String[] args) {
  • Instant naked = Instant.parse("2000-01-01T12:00:01Z");
  • System.out.println(naked);
  • ZonedDateTime withTimeZone = naked.atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(withTimeZone);
  • long toSeconds = withTimeZone.toEpochSecond();
  • ZonedDateTime recreated = Instant.ofEpochSecond(toSeconds).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • recreated = Instant.ofEpochSecond(toSeconds - 1).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • // output:
  • // 2000-01-01T12:00:01Z
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00+11:00[Australia/Melbourne]
  • }
  • }
  • ```
  • The last output skips the seconds. I would call it a (strange) feature if the minutes also would be skipped, but they are displayed.
  • What is it?
  • ----
  • Thanks for the answers, in short it is:
  • * it is documented, so it is a feature, not a bug
  • * you can easily circumvent that feature by specifying explicitly what format you want to have
#3: Post edited by user avatar watchmaker‭ · 2025-11-12T22:21:54Z (10 months ago)
short summerization of the answers
  • When printing a `java.time.ZonedDateTime`, it's missing the seconds in output, is it a bug or a feature?
  • See my code:
  • ```java
  • package tryNcry;
  • import java.time.Instant;
  • import java.time.ZoneId;
  • import java.time.ZonedDateTime;
  • public class TestOfTime {
  • public static void main(String[] args) {
  • Instant naked = Instant.parse("2000-01-01T12:00:01Z");
  • System.out.println(naked);
  • ZonedDateTime withTimeZone = naked.atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(withTimeZone);
  • long toSeconds = withTimeZone.toEpochSecond();
  • ZonedDateTime recreated = Instant.ofEpochSecond(toSeconds).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • recreated = Instant.ofEpochSecond(toSeconds - 1).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • // output:
  • // 2000-01-01T12:00:01Z
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00+11:00[Australia/Melbourne]
  • }
  • }
  • ```
  • The last output skips the seconds. I would call it a (strange) feature if the minutes also would be skipped, but they are displayed.
  • What is it?
  • When printing a `java.time.ZonedDateTime`, it's missing the seconds in output, is it a bug or a feature?
  • See my code:
  • ```java
  • package tryNcry;
  • import java.time.Instant;
  • import java.time.ZoneId;
  • import java.time.ZonedDateTime;
  • public class TestOfTime {
  • public static void main(String[] args) {
  • Instant naked = Instant.parse("2000-01-01T12:00:01Z");
  • System.out.println(naked);
  • ZonedDateTime withTimeZone = naked.atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(withTimeZone);
  • long toSeconds = withTimeZone.toEpochSecond();
  • ZonedDateTime recreated = Instant.ofEpochSecond(toSeconds).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • recreated = Instant.ofEpochSecond(toSeconds - 1).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • // output:
  • // 2000-01-01T12:00:01Z
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00+11:00[Australia/Melbourne]
  • }
  • }
  • ```
  • The last output skips the seconds. I would call it a (strange) feature if the minutes also would be skipped, but they are displayed.
  • What is it?
  • ----
  • Tanks for the answers, in short it is:
  • * it is documented, so it is a feature, not a bug
  • * you can easily circumvent that feature by specifying explicitly what format you want to have
#2: Post edited by user avatar hkotsubo‭ · 2025-11-12T21:10:32Z (10 months ago)
added tag / minor fixes
java.time.ZonedDateTime missing seconds in output
  • Java.time.ZonedDateTime missing seconds in output, is it a bug or a feature?
  • See my code:
  • ```
  • package tryNcry;
  • import java.time.Instant;
  • import java.time.ZoneId;
  • import java.time.ZonedDateTime;
  • public class TestOfTime {
  • public static void main(String[] args) {
  • Instant naked = Instant.parse("2000-01-01T12:00:01Z");
  • System.out.println(naked);
  • ZonedDateTime withTimeZone = naked.atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(withTimeZone);
  • long toSeconds = withTimeZone.toEpochSecond();
  • ZonedDateTime recreated = Instant.ofEpochSecond(toSeconds).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • recreated = Instant.ofEpochSecond(toSeconds - 1).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • // output:
  • // 2000-01-01T12:00:01Z
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00+11:00[Australia/Melbourne]
  • }
  • }
  • ```
  • The last output skips the seconds. I would call it a (strange) feature if the minutes also would be skipped, but they are displayed.
  • What is it?
  • When printing a `java.time.ZonedDateTime`, it's missing the seconds in output, is it a bug or a feature?
  • See my code:
  • ```java
  • package tryNcry;
  • import java.time.Instant;
  • import java.time.ZoneId;
  • import java.time.ZonedDateTime;
  • public class TestOfTime {
  • public static void main(String[] args) {
  • Instant naked = Instant.parse("2000-01-01T12:00:01Z");
  • System.out.println(naked);
  • ZonedDateTime withTimeZone = naked.atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(withTimeZone);
  • long toSeconds = withTimeZone.toEpochSecond();
  • ZonedDateTime recreated = Instant.ofEpochSecond(toSeconds).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • recreated = Instant.ofEpochSecond(toSeconds - 1).atZone(ZoneId.of("Australia/Melbourne"));
  • System.out.println(recreated);
  • // output:
  • // 2000-01-01T12:00:01Z
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00:01+11:00[Australia/Melbourne]
  • // 2000-01-01T23:00+11:00[Australia/Melbourne]
  • }
  • }
  • ```
  • The last output skips the seconds. I would call it a (strange) feature if the minutes also would be skipped, but they are displayed.
  • What is it?
#1: Initial revision by user avatar watchmaker‭ · 2025-11-11T05:59:17Z (10 months ago)
java.time.ZonedDateTime missing seconds in output
Java.time.ZonedDateTime missing seconds in output, is it a bug or a feature?

See my code:
```
package tryNcry;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class TestOfTime {

	public static void main(String[] args) {
		Instant naked = Instant.parse("2000-01-01T12:00:01Z");
		System.out.println(naked);
		ZonedDateTime withTimeZone = naked.atZone(ZoneId.of("Australia/Melbourne"));
		System.out.println(withTimeZone);

		long toSeconds = withTimeZone.toEpochSecond();
		ZonedDateTime recreated = Instant.ofEpochSecond(toSeconds).atZone(ZoneId.of("Australia/Melbourne"));
		System.out.println(recreated);
		recreated = Instant.ofEpochSecond(toSeconds - 1).atZone(ZoneId.of("Australia/Melbourne"));
		System.out.println(recreated);
// output:
//		2000-01-01T12:00:01Z
//		2000-01-01T23:00:01+11:00[Australia/Melbourne]
//		2000-01-01T23:00:01+11:00[Australia/Melbourne]
//		2000-01-01T23:00+11:00[Australia/Melbourne]		 
	}
}
```

The last output skips the seconds. I would call it a (strange) feature if the minutes also would be skipped, but they are displayed.

What is it?