Java Program to get first Friday in a month


At first, set a date −

LocalDate date = LocalDate.of(2019, Month.APRIL, 1);

Now, get the first Friday using the firstInMonth() method. Here, you have to set DayOfWeek as Friday since we want the first Friday in a month −

LocalDate firstFriday = date.with(TemporalAdjusters.firstInMonth(DayOfWeek.FRIDAY));

Example

 Live Demo

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
public class Demo {
   public static void main(String[] args) {
      LocalDate date = LocalDate.of(2019, Month.APRIL, 1);
      System.out.println("Current date = "+date);
      LocalDate firstFriday = date.with(TemporalAdjusters.firstInMonth(DayOfWeek.FRIDAY));
      System.out.println("First Friday date = "+firstFriday);
   }
}

Output

Current date = 2019-04-01
First Friday date = 2019-04-05

Updated on: 30-Jul-2019

444 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements