Java Program to adjust LocalDate to first Day of Month with TemporalAdjusters class


Let us first set a date −

LocalDate localDate = LocalDate.of(2019, Month.APRIL, 10);

Now, adjust LocalDate to first Day of Month −

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

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.APRIL, 10);
      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);
   }
}

Output

Current Date = 2019-04-10
Current Month = APRIL
First day of month = 2019-04-01

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

717 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements