package com.tuoheng.admin.utils;

import java.util.concurrent.TimeUnit;

public class TimeUtil {

    /**
     *
     * @param milliseconds 毫秒
     * @return
     */
    public static String getFormatFlyTime(long milliseconds){

         long day = TimeUnit.MILLISECONDS.toDays(milliseconds);

         long hours = TimeUnit.MILLISECONDS.toHours(milliseconds)
                - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(milliseconds));

         long minutes = TimeUnit.MILLISECONDS.toMinutes(milliseconds)
                - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(milliseconds));

         long seconds = TimeUnit.MILLISECONDS.toSeconds(milliseconds)
                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliseconds));
        System.out.println("milliseconds :" + milliseconds);

        if(day!=0L){
            return String.format("%d 天 %d 时 %d 分 %d 秒", day, hours, minutes, seconds);
        }else if(hours!=0L){
            return String.format("%d 时 %d 分 %d 秒", hours, minutes, seconds);
        }else if(minutes!=0L ){
            return String.format("%d 分 %d 秒", minutes, seconds);
        }else{
            return String.format("%d 秒",seconds);
        }
    }

    public static void main(String[] args) {
        System.out.println(getFormatFlyTime(10000));
    }
}
