急求

解决方案 »

  1.   

    /**
         * 计算两个日期之间的差
         * 注意两个日期格式必须相同
         * @param startDate 字符串开始时间
         * @param endDate 字符串结束时间
         * @param format 时间格式
         * @return int  相差天数
         * @throws ParseException
         */
        public int countDays(String startDate, String endDate, String format)
            throws ParseException
        {
            SimpleDateFormat sf = new SimpleDateFormat(format) ;
            Date sDate = sf.parse(startDate) ;
            Date eDate = sf.parse(endDate) ;
            Calendar c = Calendar.getInstance() ;        return (int) ((eDate.getTime()-sDate.getTime())/(24*3600*1000));
        }
      

  2.   

    2个DATE如date1和date2
    计算其差:
    long i = (date1.getTime() - date2.getTime()) / 1000 / 60 / 60 / 24;
    得到的i是以日为单位的,你可以调整上面的式子