How to obtain the end of the day when given a LocalDate?

java, java-time

Solution

Here are a few alternatives, depending on what you need:

LocalDate.now().atTime(23, 59, 59);     //23:59:59
LocalDate.now().atTime(LocalTime.MAX);  //23:59:59.999999999

But there is no built-in method.

As commented by @JBNizet, if you want to create an interval, you can also use an interval up to midnight, exclusive.

Problem

How to obtain the end of the day when given a LocalDate? I could get it by doing ``` LocalDateTime.of(LocalDate.now(), LocalTime.of(23, 59, 59)); ``` But is there an equivalent 'atStartOfDay' method for the end of the day? ``` LocalDate.now().atStartOfDay(); LocalDate.now().atEndOfDay(); //doesn't work ```

Original source

Related problems