In the Joda-Time library, the DateTime class offers a method withTimeAtStartOfDay to get the first moment of the day. You might think of that moment as \"midnight\". That first
TemporalAdjuster
Every LocalTime is also a TemporalAdjuster, so if can be passed to the with()
method of most temporal types and will update the time fields to match.
That is:
@Test
public void date_time_at_start_of_day() throws Exception {
assertThat(LocalDateTime.parse("2015-05-22T12:27:00")
.with(LocalTime.MIDNIGHT),
equalTo(LocalDateTime.parse("2015-05-22T00:00:00")));
assertThat(OffsetDateTime.parse("2015-05-22T12:27:00+01:00")
.with(LocalTime.MIDNIGHT),
equalTo(OffsetDateTime.parse("2015-05-22T00:00:00+01:00")));
assertThat(ZonedDateTime.parse("2015-05-22T12:27:00+01:00[Europe/London]")
.with(LocalTime.MIDNIGHT),
equalTo(ZonedDateTime.parse("2015-05-22T00:00:00+01:00[Europe/London]")));
}