Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get date of first Wednesday of a month java calendar

Tags:

java

calendar

How would I get the date of the next first Wednesday of the month using the java calendar class. For example:

Today(24/03/2012) the next first Wednesday will be 04/04/2012
On(05/04/2012) the next first Wednesday will be 02/05/2012

thanks.

like image 958
user667430 Avatar asked Sep 05 '25 03:09

user667430


1 Answers

LocalDate & DayOfWeek

In Java 8 and later, we can use the java.time classes including LocalDate and TemporalAdjusters, and the DayOfWeek enum. See Tutorial.

LocalDate firstSundayOfNextMonth = 
        LocalDate
              .now()
              .with( TemporalAdjusters.firstDayOfNextMonth() )
              .with( TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY) );
like image 128
KayV Avatar answered Sep 07 '25 22:09

KayV