Here you can find the source of formatTimeDifference(long time1, long time2)
public static String formatTimeDifference(long time1, long time2)
//package com.java2s; //License from project: Open Source License public class Main { public static String formatTimeDifference(long time1, long time2) { return formatTime(getTimeDifference(time1, time2)); }//from w ww . j a v a 2 s . c om public static String formatTime(long time) { StringBuilder ret = new StringBuilder(); int days = (int) Math.floor(time / (1000 * 3600 * 24)); int hours = (int) Math.floor((time % (1000 * 3600 * 24)) / (1000 * 3600)); int minutes = (int) Math.floor((time % (1000 * 3600 * 24)) % (1000 * 3600) / (1000 * 60)); int seconds = (int) Math.floor(time % (1000 * 3600 * 24) % (1000 * 3600) % (1000 * 60) / 1000); if (days != 0) ret.append(days + "d"); if (hours != 0 || days != 0) ret.append(hours + "h"); if (minutes != 0 || hours != 0 || days != 0) ret.append(minutes + "m"); ret.append(seconds + "s"); return ret.toString(); } public static long getTimeDifference(long time1, long time2) { return (time2 - time1); } }