Java Data Type How to - Adjust LocalDate to last Day Of Month








Question

We would like to know how to adjust LocalDate to last Day Of Month.

Answer

// ww w. ja  va 2 s . c  o  m
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;

public class Main {
  public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, Month.FEBRUARY, 25); // 2014-02-25

    // last day of February 2014 (2014-02-28)
    LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
    System.out.println(lastDayOfMonth);
  }
}

The code above generates the following result.