Java 8 – How to find Date on the day of given Week in a month ?

In this Java 8 program we will see how to find date on the day of given week in a month. For example if we want to find the date on 3rd Wednesday of current month.

 

/**
 * Created on Dec 01, 2016 Copyright(c) http://kodehelp.com All Rights Reserved.
 */
package com.kodehelp.java.util;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

/**
 * @author http://kodehelp.com
 */
public class DateTimeJava8 {

    public static void main(String args[]){

        LocalDate localDate = LocalDate
                                    .now()
                                    .with(TemporalAdjusters.dayOfWeekInMonth(3, DayOfWeek.WEDNESDAY));

        System.out.println(localDate);
    }
}

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.