Returns LocalDate date of the last day of month to which provided date belongs to. - Java java.time

Java examples for java.time:Month

Description

Returns LocalDate date of the last day of month to which provided date belongs to.

Demo Code


//package com.java2s;

import java.time.LocalDate;

public class Main {
    /**//from  w  ww. j  av  a2  s. c  o m
     * Returns {@link LocalDate} date of the last day of month to which provided {@code date} belongs to.
     */
    public static LocalDate getMonthLastDay(LocalDate date) {
        int daysInMonth = date.getMonth().length(date.isLeapYear());
        return date.withDayOfMonth(daysInMonth);
    }
}

Related Tutorials