Created
November 13, 2019 20:21
-
-
Save ColadaFF/41180043175c90515474a0f9de059971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Date atStartOfDay(Date date) { | |
LocalDateTime localDateTime = dateToLocalDateTime(date); | |
LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN); | |
return localDateTimeToDate(startOfDay); | |
} | |
public static Date atEndOfDay(Date date) { | |
LocalDateTime localDateTime = dateToLocalDateTime(date); | |
LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX); | |
return localDateTimeToDate(endOfDay); | |
} | |
private static LocalDateTime dateToLocalDateTime(Date date) { | |
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); | |
} | |
private static Date localDateTimeToDate(LocalDateTime localDateTime) { | |
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment