一个倒计时显示的毫秒数(模仿拼多多)
Posted WidgetBox
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个倒计时显示的毫秒数(模仿拼多多)相关的知识,希望对你有一定的参考价值。
直接上干货
/** * 毫秒倒计时成时 分 秒的形式 * @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)
磊磊
以上是关于一个倒计时显示的毫秒数(模仿拼多多)的主要内容,如果未能解决你的问题,请参考以下文章