Java long calculate elapsed time
public class Main { public static void main(String[] args) throws Exception { // Get current time long start = System.currentTimeMillis(); System.out.println(start);// w ww. j av a 2 s . c o m // Do something ... start -= 124123123; // Get elapsed time in milliseconds long elapsedTimeMillis = System.currentTimeMillis() - start; System.out.println("elapsedTimeMillis:"+elapsedTimeMillis); // Get elapsed time in seconds float elapsedTimeSec = elapsedTimeMillis / 1000F; System.out.println("elapsedTimeSec:"+elapsedTimeSec); // Get elapsed time in minutes float elapsedTimeMin = elapsedTimeMillis / (60 * 1000F); System.out.println("elapsedTimeMin:"+elapsedTimeMin); // Get elapsed time in hours float elapsedTimeHour = elapsedTimeMillis / (60 * 60 * 1000F); System.out.println("elapsedTimeHour:"+elapsedTimeHour); // Get elapsed time in days float elapsedTimeDay = elapsedTimeMillis / (24 * 60 * 60 * 1000F); System.out.println("elapsedTimeDay:"+elapsedTimeDay); } }