时间区间计算工具类

本文介绍了如何使用Hutool工具包进行时间区间的计算和操作,适用于Java开发者提高时间处理效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需要引用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);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值