java倒计时,使用Timer

来源:互联网 发布:网络布线教程 编辑:程序博客网 时间:2024/06/05 17:55

记录下工作中用到的

public void Time(Integer num){        int min = num;        long start = System.currentTimeMillis();        final long end = start+min*60*1000;        final Timer timer = new Timer();        timer.schedule(new TimerTask() {            @Override            public void run() {                long show = end-System.currentTimeMillis();                long hh = show/1000/60/60;                long mm = show/1000/60%60;                long ss = show/1000%60;                System.out.println(hh+"时"+mm+"分"+ss+"秒");            }        //倒计时结束取消订单        timer.schedule(new TimerTask() {            @Override            public void run() {                System.out.println("取消订单");                timer.cancel();            }        },new Date(end));    }
原创粉丝点击