• 一个倒计时显示的毫秒数(模仿拼多多)


    直接上干货

    /**
         * 毫秒倒计时成时 分 秒的形式
         * @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)


    磊磊
  • 相关阅读:
    Linux 套接字编程
    Linux 网络(连接)相关参数作用
    Python WSGI
    Ubuntu Cloud Image in Openstack
    AWK
    MySQL--开发技巧(一)
    spring MVC--配置注解
    javascript-JQuery样式篇(一)
    JSP--常用标签
    spring MVC basic
  • 原文地址:https://www.cnblogs.com/widgetbox/p/12122844.html
Copyright © 2020-2023  润新知