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.format.*;
  9. import java.time.temporal.*;
  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. ZoneId z = ZoneId.of( "America/Montreal" ) ;
  18. ZonedDateTime zdtStart = ZonedDateTime.of( 2017, 1, 23, 22, 15, 0, 0 , z );
  19. ZonedDateTime zdtStop = ZonedDateTime.of( 2017, 1, 24, 01, 15, 0, 0 , z );
  20. Duration d = Duration.between( zdtStart , zdtStop );
  21.  
  22. System.out.println( "zdtStart.toString(): " + zdtStart );
  23. System.out.println( "zdtStop.toString(): " + zdtStop );
  24. System.out.println( "d.toString(): " + d );
  25.  
  26. }
  27. }
Success #stdin #stdout 0.1s 711680KB
stdin
Standard input is empty
stdout
zdtStart.toString(): 2017-01-23T22:15-05:00[America/Montreal]
zdtStop.toString(): 2017-01-24T01:15-05:00[America/Montreal]
d.toString(): PT3H