package cn.com.ty.lift.common.utils;


import cn.hutool.core.date.DateUtil;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class DateUtils {

    /**
     * LocalDate转Date
     *
     * @param localDate
     * @return
     */
    public static Date localDate2Date(LocalDate localDate) {
        if (null == localDate) {
            return null;
        }
        ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }

    /**
     * 生成当前时间的年月日时分秒毫秒微秒
     *
     * @return
     */
    public static String generateCode() {
        return DateUtil.format(new Date(), "yyyyMMddHHmmssSSS");
    }

    public static int daysOfYear(){
        return LocalDate.now().isLeapYear() ? 366 : 365;
    }
}
