京东秒杀

@SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            if (msg.what == 0) {
                Calendar instance = Calendar.getInstance();
                int hour = instance.get(instance.HOUR_OF_DAY);
                int tohour = 2;
                if (hour % 2 == 0) {
                    h = hour + tohour;
                } else {
                    h = hour - 1 + tohour;
                }

                int minute = instance.get(Calendar.MINUTE);
                int second = instance.get(Calendar.SECOND);

//        计算时差
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");


                try {
                    Date d1 = simpleDateFormat.parse(h + ":00:00");
                    Date d2 = simpleDateFormat.parse(hour + ":" + minute + ":" + second);
                    //Date   d2 = new   Date(System.currentTimeMillis());//你也可以获取当前时间
                    long diff = d1.getTime() - d2.getTime();//这样得到的差值是微秒级别
                    long hours = (diff / (1000 * 60 * 60));
                    long minutes = (diff - hours * (1000 * 60 * 60)) / (1000 * 60);
                    long seconds = (diff - hours * (1000 * 60 * 60) - minutes * (1000 * 60)) / 1000;

                    textTime.setText(h + "点场");
                    textShi.setText(hours + ":" + minutes + ":" + seconds);

                } catch (Exception e) {
                }
                handler.sendEmptyMessageDelayed(0, 1000);
            }
        }
    };

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值