Skip to Content
Java Coding Problems
book

Java Coding Problems

by Anghel Leonard
September 2019
Intermediate to advanced
816 pages
18h 47m
English
Packt Publishing
Content preview from Java Coding Problems

75. Start and end of a day

In JDK 8, trying to find the start/end of a day can be accomplished in several ways.

Let's consider a day expressed via LocalDate:

LocalDate localDate = LocalDate.of(2019, 2, 28);

The solution to finding the start of the day February 28, 2019, relies on a method named atStartOfDay(). This method returns LocalDateTime from this date at the time of midnight, 00:00:

// 2019-02-28T00:00LocalDateTime ldDayStart = localDate.atStartOfDay();

Alternatively, the solution can use the of(LocalDate date, LocalTime time) method. This method combines the given date and time into LocalDateTime. So, if the passed time is LocalTime.MIN (the time of midnight at the start of the day) then the result will be as follows:

// 2019-02-28T00:00 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Coding Problems - Second Edition

Java Coding Problems - Second Edition

Anghel Leonard
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
The Well-Grounded Java Developer, Second Edition

The Well-Grounded Java Developer, Second Edition

Benjamin Evans, Martijn Verburg, Jason Clark

Publisher Resources

ISBN: 9781789801415Supplemental Content