JAVA DATE 计算相隔天数+日期增加减少

    //计算两日期相差天数
    public int testBetweenDays(Date opDate,Date enDate) {
        // 获取相差的天数
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(opDate);
        long timeInMillis1 = calendar.getTimeInMillis();
        calendar.setTime(enDate);
        long timeInMillis2 = calendar.getTimeInMillis();

        int betweenDays = (int) ((timeInMillis2 - timeInMillis1) / (1000L * 3600L * 24L));
        return betweenDays;
    }

    public  Date addDayOfDate(Date date,int i){
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.DATE, i);
        Date newDate = c.getTime();
        return newDate;
    }
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页