I try to prove June 30th 2015 has 86401 seconds, use Java code like this:
Instant i1 = Instant.ofEpochSecond(longestDay.toEpochSecond(ZoneOffset.UTC));
Instant i2 = Instant.ofEpochSecond(oneDayAfter.toEpochSecond(ZoneOffset.UTC));
long d = i1.until(i2, ChronoUnit.SECONDS);
System.out.println(d);
// 86400
I try again:
LocalDateTime longestDay = LocalDateTime.of(2015, Month.JUNE, 30, 0, 0, 0);
LocalDateTime oneDayAfter = LocalDateTime.of(2015, Month.JULY, 1, 0, 0, 0, 0);
long p = ChronoUnit.SECONDS.between(longestDay, oneDayAfter);
System.out.println("p = " + String.valueOf(p));
// Result: p = 86400
still not success
I still try again:
ZonedDateTime startZdt = ZonedDateTime.of( 2015, 06, 30, 23, 59, 59, 00, ZoneOffset.UTC );
ZonedDateTime stopZdt = ZonedDateTime.of( 2015, 07, 01, 00, 00, 00, 00, ZoneOffset.UTC );
long elapsed = startZdt.until( stopZdt,ChronoUnit.SECONDS);
System.out.println("elapsed: " + elapsed);
// Result: elapsed: 1
I can't prove June 30th 2015 has 86401 seconds by Java code. Help me do this!
Short answer:
No. There is no chance to prove it with java.time
(JSR-310) as you have already demonstrated.
Explanation:
Instant
which is talking about the time scale UTC-SLS (originally an expired proposal of Markus Kuhn). UTC-SLS keeps the fiction of having every day 86400 seconds by using a rubber second concept. If you take UTC-SLS seriously then you cannot observe 86401 seconds. Note: UTC-SLS != UTC.Instant
as being on the same scale as POSIX which totally ignores leap seconds. Also with this view, you only get 86400 seconds.If you nevertheless want a solution and not ignore leap seconds then the only way to observe 86401 SI-seconds on 2015-06-30 is using an external library like mine (Time4J):
PlainDate ls = PlainDate.of(2015, 6, 30);
Moment start = ls.atStartOfDay().atUTC();
Moment end = ls.plus(1, CalendarUnit.DAYS).atStartOfDay().atUTC();
System.out.println(SI.SECONDS.between(start, end)); // 86401
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With