直接上干货
/** * 毫秒倒计时成时 分 秒的形式 * @param ms * @return */ public static String[] formatSecKillTime(Long ms) { Integer ss = 1000; Integer mi = ss * 60; Integer hh = mi * 60; Long hour = (ms ) / hh; Long minute = (ms - hour * hh) / mi; Long second = (ms - hour * hh - minute * mi) / ss; Long milliSecond = (ms - hour * hh - minute * mi - second * ss)/100; String[] strings = new String[4]; String strHour = hour < 10 ? "0" + hour : "" + hour;//小时 String strMinute = minute < 10 ? "0" + minute : "" + minute;//分钟 String strSecond = second < 10 ? "0" + second : "" + second;//秒 String strMilliSecond = "" + milliSecond;//毫秒 strings[0]=strHour; strings[1]=strMinute; strings[2]=strSecond; strings[3]=strMilliSecond; return strings; }
//这里代表时分秒和分秒
String[] times = TimeHelper.formatSecKillTime(millisUntilFinished);
times[0] + ":" + times[1] + ":" + times[2] + ":" + times[3];
需要搭配倒计时的显示
public void countDownstart(long l) { if (countDownTimer == null) { countDownTimer = new CountDownTimer(l, 100) { public void onTick(long millisUntilFinished) { String[] times = TimeHelper.formatSecKillTime(millisUntilFinished); tv_countdown.setText(times[0] + ":" + times[1] + ":" + times[2] + ":" + times[3]); LogUtil.d("CountDownTimer", times[0] + ":" + times[1] + ":" + times[2] + ":" + times[3]); } public void onFinish(String redpackage_id) { LogUtil.d("CountDownTimer", "完了啊"); } }; } //使用前记得先cancel countDownTimer.cancel(); countDownTimer.setmStopTimeInFuture(l); countDownTimer.start(); }
注意的一点之前的1000这里写为100导致倒计时快了10倍,所以就可以展示评多多样式
new CountDownTimer(l, 100)
磊磊