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
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...
#4: Post edited
- 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
- 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
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
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?
