fork 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.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. LocalDateTime start = LocalDateTime.parse( "2013-07-31T10:15:01" );
  14. LocalDateTime stop = LocalDateTime.parse( "2013-08-01T11:22:33" );
  15. Duration d = Duration.between( start , stop );
  16.  
  17. System.out.println( "span: " + start.toString() + "/" + stop.toString() );
  18. System.out.println( "d.toString(): " + d );
  19.  
  20. // For extracting the parts of days or hours or minutes, see these Stack Overflow pages:
  21. // http://stackoverflow.com/a/36379046/642706
  22. // http://stackoverflow.com/q/24491243/642706
  23. }
  24. }
Success #stdin #stdout 0.26s 320832KB
stdin
Standard input is empty
stdout
span: 2013-07-31T10:15:01/2013-08-01T11:22:33
d.toString(): PT25H7M32S