您的位置:首页 > 其它

286_实现计时器功能

2016-09-29 21:43 148 查看
实现计时器功能

runnable = new Runnable() {

            @Override

            public void run() {

                if (timeLeft <= 0) {

                    tv_shengyushijian.removeCallbacks(runnable);

                } else {

                    tv_shengyushijian.setText(calCountSecs(timeLeft));

                    timeLeft -= 1000;

                    if (timeLeft >= 0) {

                        tv_shengyushijian.postDelayed(this, 1000);

                    }

                }

            }

        };

    public static String calCountSecs(long time) {

        int d = (int) (time / 1000 / 60 / 60 / 24);

        int h = (int) (time / 1000 / 60 / 60 - d * 24);

        int m = (int) ((time / 1000 / 60) - h * 60 - d * 24 * 60);

        int s = (int) (time / 1000 - m * 60 - h * 60 * 60 - d * 24 * 60 * 60);

        return String.format("%d天%02d小时%02d分%02d秒", d, h, m, s);

    }

变成详细的 多少天多少小时
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: