TemporalAdjusters lastDayOfMonth() method in Java with Examples
The lastDayOfMonth() method of a TemporalAdjusters class is used to return the “last day of the month” TemporalAdjuster object, which returns a new Date object set to the last day of the month.
Syntax:
public static TemporalAdjuster lastDayOfMonth()
Parameters: This method accepts nothing.
Return value: This method returns the last day of month adjuster, not null.
Below programs illustrate the TemporalAdjusters.lastDayOfMonth() method:
Program 1:
import java.time.LocalDate;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
TemporalAdjuster temporalAdjuster
= TemporalAdjusters.lastDayOfMonth();
LocalDate localDate
= LocalDate.of( 2020 , 05 , 11 );
LocalDate lastDayOfMonth
= localDate.with(temporalAdjuster);
System.out.println( "last day of the "
+ "month for localdate "
+ localDate + ": "
+ lastDayOfMonth);
}
}
|
Output:
last day of the month for localdate 2020-05-11: 2020-05-31
Program 2:
import java.time.LocalDate;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
TemporalAdjuster temporalAdjuster
= TemporalAdjusters
.lastDayOfMonth();
LocalDate localDate
= LocalDate.of( 2010 , 12 , 29 );
LocalDate lastDayOfMonth
= localDate.with(temporalAdjuster);
System.out.println( "last day of the "
+ "month for localdate "
+ localDate + ": "
+ lastDayOfMonth);
}
}
|
Output:
last day of the month for localdate 2010-12-29: 2010-12-31
References: https://docs.oracle.com/javase/10/docs/api/java/time/format/TemporalAdjusters.html
Last Updated :
27 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...