比较日期大小
date1.compareTo(date2)
日期时间差
private static long daysBetween(Date one, Date two) {
long difference = (one.getTime()-two.getTime())/86400000;
return Math.abs(difference);
}
增加减少天数
/**
* 获取某天的时间
* @param index 为正表示当前时间加天数,为负表示当前时间减天数
* @return String
*/
public static String getTimeDay( int index){
TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
TimeZone.setDefault(tz);
Calendar calendar = Calendar.getInstance();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
calendar.add(Calendar.DAY_OF_MONTH,index);
String date = fmt.format(calendar.getTime());
return date;
}