package com.sonic.common.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

/**
 * @author code
 * @date 2020-06-04
 */
public class DateUtils {
    private static final ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault();

    public static LocalDateTime toLocalDateTime(Date date) {
        Instant instant = date.toInstant();
        return instant.atZone(DEFAULT_ZONE_ID).toLocalDateTime();
    }

    public static Date toDate(LocalDateTime localDateTime) {
        ZonedDateTime zdt = localDateTime.atZone(DEFAULT_ZONE_ID);
        return Date.from(zdt.toInstant());
    }

}
