1.Java日期加一天,
/** * 增加一天 * @param s * @param n * @return */ public static String addDay(String s, int n) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd"); Calendar cd = Calendar.getInstance(); cd.setTime(sdf.parse(s)); cd.add(Calendar.DATE, n); return sdf2.format(cd.getTime()); } catch (Exception e) { return null; } }2.Java 计算日期差 ,
/** * 计算两个日期差 * @param date1 * @param date2 * @return */ public static int datediff(Date date1,Date date2) { int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24)); return Math.abs(days); }