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.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15.  
  16. String s =
  17. LocalTime.MIN.plus(
  18. Duration.between(
  19. LocalTime.of( 12 , 5 , 0 ) ,
  20. LocalTime.of( 12 , 7 , 0 )
  21. )
  22. ).toString();
  23. System.out.println( s );
  24.  
  25. LocalTime start = LocalTime.now( ZoneId.of( "America/Montreal" ) );
  26. LocalTime stop = start.plusMinutes( 7 );
  27. Duration d = Duration.between( start , stop );
  28. LocalTime result = LocalTime.MIN.plus( d ); // I do *not* recommend abusing `LocalTime` this way. Use `Duration` instead.
  29. DateTimeFormatter f = DateTimeFormatter.ISO_LOCAL_TIME ;
  30. String output = result.format( f );
  31. System.out.println( "output: " + output );
  32.  
  33. }
  34. }
Success #stdin #stdout 0.11s 712192KB
stdin
Standard input is empty
stdout
00:02
output: 00:07:00