//获取相隔天数 /**get the days of the gap of the tow date * @param beforedate * @param afterdate * @return * @throws ParseException */ static public long getDistinceDay(String beforedate, String afterdate) throws ParseException { SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd"); long dayCount=0; try{ java.util.Date d1 = d.parse(beforedate); java.util.Date d2 = d.parse(afterdate); dayCount = (d2.getTime()-d1.getTime())/(24*60*60*1000); }catch(ParseException e){ System.out.println("Date parse error!"); } return dayCount; } //该片段来自于http://yuncode.net