Java Data Type How to - Adjust LocalDate to first Day Of next month








Question

We would like to know how to adjust LocalDate to first Day Of next month.

Answer

import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
// ww  w  . ja  v  a 2  s.c  o  m
public class Main {
  public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, Month.FEBRUARY, 25); // 2014-02-25

    // first day of next month (2014-03-01)
    LocalDate firstDayOfNextMonth = date.with(TemporalAdjusters.firstDayOfNextMonth());
    
    System.out.println(firstDayOfNextMonth);
  }
}

The code above generates the following result.