需要引用hutool工具包
/**
* 时间区间计算工具类
*/
public class TimeIntervalUtil {
/**
* 昨天时间上限
* @return Date
*/
public static Date getYesterdayMax() throws ParseException {
return DateUtil.endOfDay(DateUtil.yesterday());
}
/**
* 昨天时间下限
* @return Date
*/
public static Date getYesterdayMin() throws ParseException {
return DateUtil.beginOfDay(DateUtil.yesterday());
}
/**
* 今天时间上限
* @return Date
*/
public static Date getTodayMax() throws ParseException {
return DateUtil.endOfDay(new Date());
}
/**
* 今天时间下限
* @return Date
*/
public static Date getTodayMin() throws ParseException {
return DateUtil.beginOfDay(new Date());
}
/**
* 明天时间上限
* @return Date
*/
public static Date getTomorrowMax() throws ParseException {
return DateUtil.endOfDay(DateUtil.tomorrow());
}
/**
* 明天时间下限
* @return Date
*/
public static Date getTomorrowMin() throws ParseException {
return DateUtil.beginOfDay(DateUtil.tomorrow());
}
/**
* 上一周时间上限
* @return Date
*/
public static Date getLastWeekMax() throws ParseException {
return DateUtil.endOfDay(DateUtil.offset(DateUtil.date(), DateField.DAY_OF_MONTH, 7));
}
/**
* 上一周时间下限
* @return Date
*/
public static Date getLastWeekMin() throws ParseException {
return DateUtil.beginOfDay(DateUtil.lastWeek());
}
/**
* 下一周时间上限
* @return Date
*/
public static Date getNextWeekMax() throws ParseException {
return DateUtil.endOfDay(DateUtil.offset(DateUtil.nextWeek(), DateField.DAY_OF_MONTH, 7));
}
/**
* 下一周时间下限
* @return Date
*/
public static Date getNextWeekMin() throws ParseException {
return DateUtil.beginOfDay(DateUtil.nextWeek());
}
/**
* 上一个月时间上限
* @return Date
*/
public static Date getLastMonthMax() throws ParseException {
return DateUtil.endOfDay(DateUtil.offset(DateUtil.lastMonth(), DateField.MONTH, 1));
}
/**
* 上一个月时间下限
* @return Date
*/
public static Date getLastMonthMin() throws ParseException {
return DateUtil.beginOfDay(DateUtil.lastMonth());
}
/**
* 下一个月时间上限
* @return Date
*/
public static Date getNextMonthMax() throws ParseException {
return DateUtil.endOfDay(DateUtil.offset(DateUtil.nextMonth(), DateField.MONTH, 1));
}
/**
* 下一个月时间下限
* @return Date
*/
public static Date getNextMonthMin() throws ParseException {
return DateUtil.beginOfDay(DateUtil.nextMonth());
}
/**
* 时间上限
* @return Date
*/
public static Date getTimeIntervalMax(Date date) throws ParseException {
return DateUtil.endOfDay(date);
}
/**
* 时间下限
* @return Date
*/
public static Date getTimeIntervalMin(Date date) throws ParseException {
return DateUtil.beginOfDay(date);
}
}