Syntax error Java Program to adjust Adjust LocalDate to first Day Of next month with TemporalAdjusters class

Java Program to adjust Adjust LocalDate to first Day Of next month with TemporalAdjusters class



Let us first set a date −

LocalDate localDate = LocalDate.of(2019, Month.JUNE, 15);

Now, adjust LocalDate to first Day of next month −

LocalDate day = localDate.with(TemporalAdjusters.firstDayOfNextMonth());

Example

 Live Demo

import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
public class Demo {
   public static void main(String[] args) {
      LocalDate localDate = LocalDate.of(2019, Month.JUNE, 15);
      System.out.println("Current Date = "+localDate);
      System.out.println("Current Month = "+localDate.getMonth());
      LocalDate day = localDate.with(TemporalAdjusters.firstDayOfMonth());
      System.out.println("First day of month = "+day);
      day = localDate.with(TemporalAdjusters.firstDayOfNextMonth());
      System.out.println("First day of next month = "+day);
   }
}

Output

Current Date = 2019-06-15
Current Month = JUNE
First day of month = 2019-06-01
First day of next month = 2019-07-01
Updated on: 2019-07-30T22:30:25+05:30

353 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements