/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package be.neutrinet.ispng.util; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; /** * Converts between LocalDateTime -> Date LocalDate -> Date Date -> * LocalDateTime * <p> * Does not convert between Date -> LocalDate, risks loss of precision * * @author wannes */ public class DateUtil { public static Date convert(LocalDate ld) { Instant instant = ld.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(); return Date.from(instant); } public static Date convert(LocalDateTime ldt) { Instant instant = ldt.atZone(ZoneId.systemDefault()).toInstant(); return Date.from(instant); } public static LocalDateTime convert(Date date) { Instant instant = Instant.ofEpochMilli(date.getTime()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); } }