package com.ningdatech.kqapi.scheduler.utils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;

/**
 * @Classname DateUtil
 * @Description
 * @Date 2023/8/31 15:36
 * @Author PoffyZhang
 */
public class DateUtil {

    public static Date getTodayTime(int hour){
        // 获取当前日期时间
        Calendar calendar = Calendar.getInstance();

        // 将时间设置为凌晨
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);

        // 获取凌晨时间
        Date date = calendar.getTime();
        return date;
    }

    public static LocalDateTime convertDateToLocal(Date date){
        if(Objects.isNull(date)){
            return null;
        }
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
    }
}
