fork(2) 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.text.SimpleDateFormat;
  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. printDuration();
  14. }
  15.  
  16. private static String formatDuration(final long duration) {
  17. final long hh = duration / 1000 / 3600;
  18. final long mm = duration / 1000 % 3600 / 60;
  19. final long ss = duration / 1000 % 3600 % 60;
  20. return hh + "h" + ":" + mm + "m" + ":" + ss + "s";
  21. }
  22.  
  23. private static void printDuration() throws Exception {
  24. SimpleDateFormat PARSE_FORMAT = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
  25. PARSE_FORMAT.setTimeZone(TimeZone.getTimeZone("Atlantic/Bermuda"));
  26. long dayFrom = PARSE_FORMAT.parse("11/02/2014 00:00:00").getTime();
  27. long dayTo = PARSE_FORMAT.parse("11/03/2014 23:59:59").getTime();
  28. System.out.println(formatDuration(dayTo - dayFrom));
  29. }
  30. }
Success #stdin #stdout 0.1s 380928KB
stdin
Standard input is empty
stdout
48h:59m:59s