Here you can find the source of getActivityTime(long startTime, long endTime)
private static String getActivityTime(long startTime, long endTime)
//package com.java2s; public class Main { private static String getActivityTime(long startTime, long endTime) { long differenceInSeconds = endTime - startTime; //Check for seconds if (differenceInSeconds < 60) { return differenceInSeconds + "sec"; } else {// w w w .j a va2 s . c om //Check for minutes & hours long minutes = differenceInSeconds / 60; if (minutes < 60) { return minutes + "min"; } else { long hours = minutes / 60; minutes = minutes - (hours * 60); // Could be zero. return hours + "hr " + (minutes > 0 ? minutes + "min" : ""); } } } }