zoukankan      html  css  js  c++  java
  • 一个倒计时显示的毫秒数(模仿拼多多)

    直接上干货

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


    磊磊
  • 相关阅读:
    爬虫(五):生产者消费者方法
    三. Anagram detection problem for string(字符串中回文词汇检测问题)
    二. Object-Oriented Programming in Python: Defining Classes
    一.Introduction
    爬虫(四):正则表达式(提取str中网址)
    centos7源代码编译安装heartbeat
    linux yum配置
    java常见证书类型和密钥库类型
    常用的加密算法
    iptables学习理解
  • 原文地址:https://www.cnblogs.com/widgetbox/p/12122844.html
Copyright © 2011-2022 走看看