Java 领劵或月卡小demo

为什么80%的码农都做不了架构师?>>>   hot3.png

public static void main(String[] args){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar now = Calendar.getInstance();
        Calendar receiveDate = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        //当前时间
        try {
            //now.setTime(sdf.parse(sdf.format(new Date())));
            now.setTime(sdf.parse("2018-08-16"));
            System.out.println(sdf.format(now.getTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        //领劵时间
        try {
            receiveDate.setTime(sdf.parse("2018-08-10"));
            System.out.println(sdf.format(receiveDate.getTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        //劵的失效时间
        try {
            max.setTime(sdf.parse("2018-08-10"));
            max.add(Calendar.MONTH, +3);
            System.out.println(sdf.format(max.getTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        System.out.println("now.getTimeInMillis():"+now.getTimeInMillis());
        System.out.println("receiveDate.getTimeInMillis():"+receiveDate.getTimeInMillis());
        System.out.println("max.getTimeInMillis():"+max.getTimeInMillis());
        //如果当前时间大于等于领劵的失效时间
        if(now.getTimeInMillis()>= max.getTimeInMillis()){
            System.out.println(1);  //过期
        }else {//剩余天数还有几天
            System.out.println(2);
            long days = (max.getTimeInMillis() -now.getTimeInMillis())/ (1000 * 60 * 60 * 24);
            System.out.println(days);
        }


    }

 

转载于:https://my.oschina.net/saulc/blog/1928723

你可能感兴趣的:(Java 领劵或月卡小demo)