比如说计算20030623 至20060625之间的天数,谢谢

解决方案 »

  1.   

    java库没有提供直接计算两个日期之间的天数可以自己实现
        /**
         * 计算两个日期之间的差
         * 注意两个日期格式必须相同
         * @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() ;        c.setTime(sDate);
            long ls = c.getTimeInMillis() ;        c.setTime(eDate);
            long le = c.getTimeInMillis() ;        return (int) ((le-ls)/(24*3600*1000));
        }
      

  2.   

    哈哈哈
    查了下api 
    想鸡蛋里挑骨头
    发现的楼上的方法好像是最好的