将毫秒转为00:00:00的时间格式

    public static String getDateByMS(long longMS) {
        //long day = 0l;//
        long hour = 0l;//
        long minute = 0l;//
        long second = 0l;//
        String H = "00";
        String M = "00";
        String S = "00";
        //long millisecond = 0l;//毫秒
        //millisecond = longMS%1000;
        System.out.println(longMS);
        second = longMS / 1000;
        if (second >= 60) {
            minute = second / 60;
            second = second % 60;
            if (minute >= 60) {
                hour = minute / 60;
                minute = minute % 60;
            }
        }
        if (hour <= 9L) {
            H = "0" + hour;
        } else {
            H = String.valueOf(hour);
        }
        if (minute <= 9L) {
            M = "0" + minute;
        } else {
            M = String.valueOf(minute);
        }
        if (second <= 9L) {
            S = "0" + second;
        } else {
            S = String.valueOf(second);
        }
        return H + ":" + M + ":" + S;
    }

 

posted @ 2022-03-15 10:19  卷心菜的奇妙历险  阅读(209)  评论(0编辑  收藏  举报