fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.text.SimpleDateFormat;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy HH:mm", Locale.US); //("MM/dd/yyyy HH:mm:ss");
  13. format.setTimeZone(TimeZone.getTimeZone("GMT"));
  14. String cycleEndTm = "02-11-2017 17:27";
  15. String cycleStartTm = "02-11-2017 16:47";
  16.  
  17. Date d3 = format.parse(cycleEndTm);
  18. Date d4 = format.parse(cycleStartTm);
  19. long diff = d3.getTime() - d4.getTime();
  20. long diffSeconds = diff / 1000 % 60;
  21. long diffMinutes = diff / (60 * 1000) % 60;
  22. long diffHours = diff / (60 * 60 * 1000) % 24;
  23. long diffDays = diff / (24 * 60 * 60 * 1000);
  24. String time1 = diffDays+"."+diffHours+"."+diffMinutes+"."+diffSeconds;
  25.  
  26. System.out.println(time1);
  27. }
  28. }
Success #stdin #stdout 0.07s 2184192KB
stdin
Standard input is empty
stdout
0.0.40.0