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( "America/New_York" ) ;
  16. LocalDate ld = LocalDate.of( 2017 , Month.NOVEMBER , 5 ) ;
  17. ZonedDateTime start = ld.atStartOfDay( z ) ;
  18. ZonedDateTime stop = ld.plusDays( 1 ).atStartOfDay( z ) ;
  19. Duration d = Duration.between( start , stop ) ;
  20.  
  21. System.out.println( "America/New_York: " + start + "/" + stop + " = " + d ) ;
  22.  
  23.  
  24. ZonedDateTime startUtc = ld.atStartOfDay( ZoneOffset.UTC ) ;
  25. ZonedDateTime stopUtc = ld.plusDays( 1 ).atStartOfDay( ZoneOffset.UTC ) ;
  26. Duration dUtc = Duration.between( startUtc , stopUtc ) ;
  27.  
  28. System.out.println( "UTC: " + startUtc + "/" + stopUtc + " = " + dUtc ) ;
  29.  
  30.  
  31.  
  32. }
  33. }
Success #stdin #stdout 0.24s 2841600KB
stdin
Standard input is empty
stdout
America/New_York: 2017-11-05T00:00-04:00[America/New_York]/2017-11-06T00:00-05:00[America/New_York] = PT25H
UTC: 2017-11-05T00:00Z/2017-11-06T00:00Z = PT24H