package com.example.blu.toys.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {


    public static   String formatTime(long ms) {
        int ss = 1000;
        int mi = ss * 60;
        int hh = mi * 60;
        int 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;

        String strHour = hour < 10 ? "0" + hour : "" + hour;//小时
        String strMinute = minute < 10 ? "0" + minute : "" + minute;//分钟
        String strSecond = second < 10 ? "0" + second : "" + second;//秒
        String strMilliSecond = milliSecond < 10 ? "0" + milliSecond : "" + milliSecond;//毫秒
        strMilliSecond = milliSecond < 100 ? "0" + strMilliSecond : "" + strMilliSecond;

        return strHour+":"+strMinute + " : " + strSecond+","+strMilliSecond ;
    }

    public  static   TimeBean getTimeBeanBySecond(Long second){
        String time=   formatTime(second*1000);
        TimeBean timeBean=new TimeBean();

        String[] tims=  time.split(":");

        timeBean.setTims(tims);
        timeBean.setmHour(Integer.valueOf(tims[0].trim()));
        timeBean.setmMin(Integer.valueOf(tims[1].trim()));

        try {
            timeBean.setmSecond(Integer.valueOf(tims[2].split(",")[0].trim()));

        }catch (Exception e){
            e.printStackTrace();
        }
        return timeBean;
    }

    public static void main(String[] args) {
        System.out.println(Integer.valueOf("00"));
        TimeBean timeBean=    getTimeBeanBySecond(0l);
        System.out.printf(  timeBean.getmHour()+":"+  timeBean.getmMin()+":"+timeBean.getmSecond());


    }
}
