public static Instant toInstant(Date date) {
return Instant.ofEpochMilli(date.getTime());
}
public static Date toDate(Instant instant) {
return new Date(instant.toEpochMilli());
}
public static Date toDate(LocalDateTime ldt) {
return new Date(ldt.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
}
public static Calendar toCalendar(ZonedDateTime zdt) {
TimeZone tz = TimeZone.getTimeZone(zdt.getZone());
Calendar calendar = Calendar.getInstance(tz);
calendar.setTimeInMillis(zdt.toInstant().toEpochMilli());
return calendar;
}
public static LocalDateTime toLocalDateTime(Date date) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
}
public static ZonedDateTime toZonedDateTime(Calendar calendar) {
ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(calendar.getTimeInMillis()), calendar.getTimeZone().toZoneId());
return zdt;
}