added getUtcDate methods
This commit is contained in:
@ -22,6 +22,10 @@ public class DateUtil {
|
||||
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
public static Date getUtcDate(final LocalDate localDate) {
|
||||
return Date.from(localDate.atStartOfDay(ZoneId.of("UTC")).toInstant());
|
||||
}
|
||||
|
||||
public static LocalDate getDate(final Date date) {
|
||||
if (date == null)
|
||||
return null;
|
||||
@ -32,4 +36,14 @@ public class DateUtil {
|
||||
return zdt.toLocalDate();
|
||||
}
|
||||
|
||||
public static LocalDate getUtcDate(final Date date) {
|
||||
if (date == null)
|
||||
return null;
|
||||
// ensure to call toInstant on java.util.Date and not on java.sql.Date because this will throw an UnsupportedOperationException
|
||||
// see Java doc of java.sql.Date.toInstant()
|
||||
Instant instant = new java.util.Date(date.getTime()).toInstant();
|
||||
ZonedDateTime zdt = instant.atZone(ZoneId.of("UTC"));
|
||||
return zdt.toLocalDate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user