時間計算

 

/*
     * 毫秒轉化時分秒毫秒
     */
    public static String formatTime(Long ms) {
        Integer ss = 1000;
        Integer mi = ss * 60;
        Integer hh = mi * 60;
        Integer dd = hh * 24;

        Long day = ms / dd;
        Long hour = (ms - day * dd) / hh;
        Long minute = (ms - day * dd - hour * hh) / mi;
        Long second = (ms - day * dd - hour * hh - minute * mi) / ss;
        Long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;

        StringBuffer sb = new StringBuffer();
            sb.append(day+"天");
            sb.append(hour+"小時");
            sb.append(minute+"分");
            sb.append(second+"秒");
            sb.append(milliSecond+"毫秒");
        return sb.toString();
    }
相關文章
相關標籤/搜索