Creates a new date object with the last day of the same month as the given date. - Java java.time

Java examples for java.time:Month

Description

Creates a new date object with the last day of the same month as the given date.

Demo Code


//package com.java2s;

import java.time.LocalDate;

public class Main {
    /**//from   w  w  w .j a  v  a  2 s  .c  om
     * Creates a new date object with the last day of the same month as the
     * given date.
     */
    public static LocalDate endOfMonth(LocalDate date) {
        return date.withDayOfMonth(date.lengthOfMonth());
    }
}

Related Tutorials