fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. ZoneId z = ZoneId.of( "Pacific/Auckland" ) ;
  16. LocalDate ld = LocalDate.of( 2021 , Month.SEPTEMBER , 26 ) ;
  17. ZonedDateTime zdtStart = ld.atStartOfDay( z ) ;
  18. Instant instantStart = zdtStart.toInstant() ;
  19. long start = instantStart.getEpochSecond() ;
  20.  
  21. LocalDate nextDay = ld.plusDays( 1 ) ;
  22. ZonedDateTime zdtEnd = nextDay.atStartOfDay( z ) ;
  23. Instant instantEnd = zdtEnd.toInstant() ;
  24. long end = instantEnd.getEpochSecond() ;
  25.  
  26. Duration d = Duration.between( zdtStart , zdtEnd ) ; // 23 hours, not 24, for Daylight Saving Time (DST) cut-over on that date in that zone.
  27.  
  28. System.out.println( zdtStart + "/" + zdtEnd ) ;
  29. System.out.println( d ) ;
  30. System.out.println( instantStart + "/" + instantEnd ) ;
  31. System.out.println( start + "/" + end ) ;
  32.  
  33. }
  34. }
Success #stdin #stdout 0.15s 56232KB
stdin
Standard input is empty
stdout
2021-09-26T00:00+12:00[Pacific/Auckland]/2021-09-27T00:00+13:00[Pacific/Auckland]
PT23H
2021-09-25T12:00:00Z/2021-09-26T11:00:00Z
1632571200/1632654000