Java Data Type How to - Get the date of last day from current month with TemporalAdjuster








Question

We would like to know how to get the date of last day from current month with TemporalAdjuster.

Answer

//w ww . ja  va  2s.c  o  m
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

public class Main {
  public static void main(String[] argv) {
    DayOfWeek d = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth())
        .getDayOfWeek();
    System.out.println(d);
  }
}

The code above generates the following result.