java计算时间

TimeUtils.timeTransfer(System.currentTimeMillis() - loadTime)
long loadTime = 0;
public static String timeTransfer(long time) {
        long hour = 0, minute = 0, second = 0, ms = 0;
        if (time > 60 * 60 * 1000 ) {
            ms = time % 1000;
            second = (time / 1000) % 60;
            minute = (time / (60*1000)) % 60;
            hour = (time / (60*60*1000)) % 60;
        } else if (time > 60 * 1000) {
            ms = time % 1000;
            second = (time / 1000) % 60;
            minute = (time / (60*1000)) % 60;
        } else if (time > 1000) {
            ms = time % 1000;
            second = (time / 1000) % 60;
        } else {
            ms = time % 1000;
        }

        return hour + "h" + minute + "m" + second + "s" + ms + "ms";
    }

 

你可能感兴趣的:(java计算时间)