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
The atEndOfMonth() method of YearMonth class in Java is used to return a LocalDate of the last day of month based on this YearMonth object with which it is used.
The getHour() method of an LocalDateTime class is used to return the hour-of-day field. This method returns an integer value ranging from 0 to 23, i.e. the Hours of a day.
Getting the Start of Day Get the start of a date using atStartOfDay() method in the local timezone as well as in a specific timezone. //The date for which start of day needs to be found LocalDate localDate = LocalDate. now(); //Local date time LocalDateTime startOfDay = localDate.
The getDayOfWeek() method of a ZonedDateTime class is used to get the day-of-week field from this ZonedDateTime, which is an enum DayOfWeek. Additional information can be obtained from the DayOfWeek.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With