如果您想要实际的午夜 (00:00),您可以使用:
instant.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS);
Run Code Online (Sandbox Code Playgroud)
否则,另一个解决方案是:
LocalDateTime ldt1 = LocalDateTime.ofInstant(instant.plus(1, ChronoUnit.DAYS), ZoneId.systemDefault());
ldt1 = ldt1
.withHour(23)
.withMinute(59)
.withSecond(59);
Instant result = ldt1.atZone(ZoneId.systemDefault()).toInstant();
Run Code Online (Sandbox Code Playgroud)
一种方法是转换Instant为时ZonedDateTime区UTC并根据要求修改日期,然后将其转换回来
正午 :
Instant result = instant.atOffset(ZoneOffset.UTC)
.plusDays(1).with(LocalTime.of(11,59,59,instant.getNano()))
.toInstant();
Run Code Online (Sandbox Code Playgroud)
一天的结束 :
Instant result = instant.atOffset(ZoneOffset.UTC)
.plusDays(1).with(LocalTime.of(23,59,59,instant.getNano()))
.toInstant();
Run Code Online (Sandbox Code Playgroud)