package org.jebot.util;

import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    // 添加或减少分钟
    public static Date addMinutes(Date date, int minutes) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, minutes);
        return calendar.getTime();
    }

    // 获取当天 00:00
    public static Date getTodayMidnight(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

//当前时间前一天的最后一秒
    public static Date getYesnight() {
        Calendar calendar = Calendar.getInstance();
// 回到前一天
        calendar.add(Calendar.DAY_OF_MONTH, -1);
// 设置到 23:59:59
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);

        Date endDate = calendar.getTime();
        return endDate;
    }
}
