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.  
  14. LocalDateTime primeiraData = LocalDateTime.of(2017, Month.JANUARY, 10, 14, 00, 00);
  15. LocalDateTime segundaDate = LocalDateTime.of(2017, Month.JANUARY, 10, 16, 30, 00);
  16.  
  17. Duration testeDuration = Duration.between(primeiraData, segundaDate);
  18. long s = testeDuration.getSeconds();
  19. System.out.println("Resultado: " + String.format("%d:%02d", s / 3600, (s % 3600) / 60));
  20.  
  21.  
  22. }
  23. }
Success #stdin #stdout 0.09s 711680KB
stdin
Standard input is empty
stdout
Resultado: 2:30