fork(4) 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. Instant start = Instant.now() ;
  15. Instant stop = start.plusSeconds( 135L ) ;
  16.  
  17. Duration d = Duration.between( start , stop ) ;
  18.  
  19. long minutesPart = d.toMinutes();
  20. long secondsPart = d.minusMinutes( minutesPart ).getSeconds() ;
  21.  
  22. System.out.println( "Interval: " + start + "/" + stop );
  23. System.out.println( "d.toString(): " + d );
  24. System.out.println( "d.getSeconds(): " + d.getSeconds() );
  25. System.out.println( "Elapsed: " + minutesPart + "M " + secondsPart + "S" );
  26. }
  27. }
Success #stdin #stdout 0.1s 711680KB
stdin
Standard input is empty
stdout
Interval: 2016-12-18T08:39:34.099Z/2016-12-18T08:41:49.099Z
d.toString(): PT2M15S
d.getSeconds(): 135
Elapsed: 2M 15S