fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.time.*;
  7. import java.time.format.*;
  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. Duration d =
  16. Duration.between(
  17. ZonedDateTime.of(
  18. LocalDate.parse( "26/02/2011" , DateTimeFormatter.ofPattern( "dd/MM/uuuu" ) ) ,
  19. LocalTime.parse( "11:00 AM" , DateTimeFormatter.ofPattern( "hh:mm a" ) ) ,
  20. ZoneId.of( "America/Montreal" )
  21. )
  22. ,
  23. ZonedDateTime.of(
  24. LocalDate.parse( "27/02/2011" , DateTimeFormatter.ofPattern( "dd/MM/uuuu" ) ) ,
  25. LocalTime.parse( "12:15 AM" , DateTimeFormatter.ofPattern( "hh:mm a" ) ) ,
  26. ZoneId.of( "America/Montreal" )
  27. )
  28. );
  29. System.out.println( "d: " + d.toString() );
  30.  
  31. // TIP: For this kind of work, you may find the `Interval` class handy. See the `ThreeTen-Extra` project.
  32.  
  33. }
  34. }
Success #stdin #stdout 0.12s 712192KB
stdin
Standard input is empty
stdout
d: PT13H15M