Java 比较两日期相差天数

(版本1)

publicstaticint getIntervalDays(Date fDate, Date oDate) {

       if (null == fDate || null == oDate) {

           return -1;

       }

       long intervalMilli = oDate.getTime() - fDate.getTime();

       return (int) (intervalMilli / (24 * 60 * 60 * 1000));

    }

  

 

    (版本2)

publicstaticint daysOfTwo(Date fDate, Date oDate) {

       Calendar aCalendar = Calendar.getInstance();

       aCalendar.setTime(fDate);

       int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);

       aCalendar.setTime(oDate);

       int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);

       return day2 - day1;

    }
上一篇:salesforce 零基础学习(三十九) soql函数以及常量


下一篇:Xocde4与Xcode3的模板比较