I want to get the milliseconds truncated to days, I can use
Instant.now().truncatedTo(ChronoUnit.DAYS).toEpochMilli()
But I can't truncate to ChronoUnit.MONTH
(it throws an exception). Do I need use a Calendar?
LocalDate getMonth() method in JavaThe getMonth() method of LocalDate class in Java gets the month-of-year field using the Month enum.
The getDayOfMonth() method returns the day represented by the given date, getMonth() method returns the month represented by the given date, and getYear() method returns the year represented by the given date.
This is what java.time.temporal.TemporalAdjusters
are for.
date.with(TemporalAdjusters.firstDayOfMonth()).truncatedTo(ChronoUnit.DAYS);
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