Java tutorial
//package com.java2s; import java.util.Date; public class Main { public static String getWasteTime(Date fromDate) { return getWasteTime(fromDate, new Date()); } public static String getWasteTime(Date startDate, Date endDate) { long wt = endDate.getTime() - startDate.getTime(); if (wt < 1000) { return wt + "ms"; } else if (wt < 60000) { long ms = wt % 1000; return ((wt - ms) / 1000) + "s " + ms + "ms"; } else { long ms = wt % 1000; long s = (wt - ms) % 60; return ((wt - s - ms) / 60000) + "m " + s + "s " + ms + "ms"; } } }