What is the proposed way to get midnight in UTC for a given period of time in milliseconds? I tried the following, which seems to work, wondering if there is a better way to do the same.
public long toUtcMidnight(final Long date) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(date), ZoneId.of("UTC"))
.toLocalDate()
.atStartOfDay()
.toInstant(ZoneOffset.UTC)
.toEpochMilli();
}
We could use Joda time for this, but for this I only want to use the java 8 date library.
source
share