localDate和Date的转化

 

/**
     * <per>
     * <p>Data 转 LocalDate</p>
     * <per/>
     * @param date
     * @return java.time.LocalDate
     * @throws
     * @Description : TODO Data transfer LocalDate
     * @author Liruilong
     * @Date 2020/11/4 9:56
     **/
    public static LocalDate date2LocalDate(Date date) {
        return Objects.isNull(date) ? null : date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }


    /**
     * <per>
     * <p>localDate 转 Date</p>
     * <per/>
     * @param localDate
     * @return java.util.Date
     * @throws
     * @Description : TODO localDate transfer Date
     * @author Liruilong
     * @Date 2020/11/4 9:58
     **/
    public static Date localDate2Date(LocalDate localDate) {
        return  Objects.isNull(localDate) ? null : Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }

    /**
    * <per>
    * <p>localDateTime 转 Date</p>
    * <per/>
    * @param localDateTime
    * @return java.util.Date
    * @throws
    * @Description : TODO localDateTime transfer  Date
    * @author Liruilong
    * @Date 2020/11/4 10:01
    **/
    public static Date localDateTime2Date(LocalDateTime localDateTime) {
        return Objects.isNull(localDateTime) ? null : Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

 

posted @ 2020-11-09 12:50  山河已无恙  阅读(513)  评论(0编辑  收藏  举报