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. import java.time.temporal.* ;
  9. import java.time.format.* ;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. ZonedDateTime start = LocalDateTime
  18. .parse( "2017-10-28T15:00:00" )
  19. .atZone( ZoneId.of( "Europe/Berlin" ) ) ; // Producing a `ZonedDateTime` instance.
  20.  
  21. ZonedDateTime stop = LocalDateTime
  22. .parse( "2017-10-29T03:00:00" )
  23. .atZone( ZoneId.of( "Europe/Berlin" ) ) ; // Producing another `ZonedDateTime` instance.
  24.  
  25. long hours = ChronoUnit.HOURS.between( start , stop ) ;
  26.  
  27. System.out.println( "start.toString(): " + start ) ;
  28. System.out.println( "stop.toString(): " + stop ) ;
  29. System.out.println( "hours: " + hours ) ;
  30.  
  31. }
  32. }
Success #stdin #stdout 0.16s 4386816KB
stdin
Standard input is empty
stdout
start.toString(): 2017-10-28T15:00+02:00[Europe/Berlin]
stop.toString(): 2017-10-29T03:00+01:00[Europe/Berlin]
hours: 13