计算两个日期相隔天数

/**
     * 计算date1间隔date2的天数
     * */
    private int getDaysBetweenTwoDates(Date date1,Date date2)throws Exception
    {
        long begin = date1.getTime();
        long end = date2.getTime();
        long inter = end - begin;
        if(inter<=0){
            return 0;
        }
        long dateMillSec = 24 * 60 * 60 * 1000;
        long datecount =  inter / dateMillSec;
        long remainder = inter % dateMillSec;
        if (remainder != 0) {
            datecount++;
        }
        return (int)datecount;
    }


你可能感兴趣的:(Date,exception)