获取指定日期的前一天
参数为String,返回String
public static String theDayBeforeStr(String dateStr) {
Calendar cal = setCalendarTime(dateStr);
cal.add(Calendar.DATE, -1);
Date beforeDate = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
return sdf.format(beforeDate);
}
参数为Date,返回String
public static String theDayBeforeStr(Date date) {
Calendar cal = setCalendarTime(dateStr);
cal.add(Calendar.DATE, -1);
Date beforeDate = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
return sdf.format(beforeDate);
}
参数为String,返回Date
public static Date theDayBeforeDate(String dateStr) {
Calendar cal = setCalendarTime(dateStr);
cal.add(Calendar.DATE, -1);
return cal.getTime();
}
参数为Date,返回Date
public static Date theDayBeforeDate(Date date) {
Calendar cal = setCalendarTime(date);
//int day = cal.get(Calendar.DATE);
//cal.set(Calendar.DATE, day-1);
/* 以下代码相当于:上面两行代码 */
cal.add(Calendar.DATE, -1);
return cal.getTime();
}
获取指定日期的下一天
参数为String,返回String
public static String theDayNextStr(String dateStr) {
Calendar cal = setCalendarTime(date);
//int day = cal.get(Calendar.DATE);
//cal.set(Calendar.DATE, day+1);
/* 以下一行代码相当于:上面两行代码 */
cal.add(Calendar.DATE, 1);
Date nextDate =cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
return sdf.format(nextDate);
}
参数为Date,返回String
public static String theDayNextStr(Date date) {
Calendar cal = setCalendarTime(date);
//int day = cal.get(Calendar.DATE);
//cal.set(Calendar.DATE, day+1);
/* 以下一行代码相当于:上面两行代码 */
cal.add(Calendar.DATE, 1);
Date nextDate = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
return sdf.format(nextDate);
}
参数为String,返回Date
public static Date theDayNextDate(String dateStr) {
Calendar cal = setCalendarTime(dateStr);
cal.add(Calendar.DATE, 1);
return cal.getTime();
}
参数为Date,返回Date
public static Date theDayNextDate(Date date) {
Calendar cal = setCalendarTime(date);
//int day = cal.get(Calendar.DATE);
//cal.set(Calendar.DATE, day+1);
/* 以下一行代码相当于:上面两行代码 */
cal.add(Calendar.DATE, 1);
return cal.getTime();
}