TemporalAdjusters Class In Java 8

Useful to add or subtract an amount of time to an Instant or a LocalDate. It is used with with() method call. For example, If we want to know next date of coming Sunday from now.

In the with method call we pass the TemporalAdjusters with next static method call passing DayOfWeek.SUNDAY as parameter.

We have 14 static methods in TemporalAdjusters class to adjust an Instant or LocalDate, like firstDayOfMonth(), lastDayOfMonth(), firstDayOfTheYear(), lastDayOfTheYear(), firstDayOfNextMonth(), firstDayOfNextYear() etc.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *