java 判断是否在五分钟之内

 Calendar c1=Calendar.getInstance();
            Calendar c2=Calendar.getInstance();
            Calendar c3=Calendar.getInstance();
            //Date date=new Date();
            c1.setTime(new Date());//要判断的日期
            c2.setTime(new Date());//初始日期
            c3.setTime(new Date());//也给初始日期 把分钟加五
            c3.add(c3.MINUTE, 5);
            c2.add(c2.MINUTE,-5);//减去五分钟
            System.out.println(c1.getTime());
            System.out.println(c2.getTime());
            System.out.println(c3.getTime());
            if(c1.after(c2)&&c1.before(c3)){
                System.out.println("五分钟之内");
            }else {
                System.out.println("五分钟之外");
            }

你可能感兴趣的:(java 判断是否在五分钟之内)