Sunday, August 2, 2026
HomeLanguagesJavaTemporalAdjusters lastDayOfYear() method in Java with Examples

TemporalAdjusters lastDayOfYear() method in Java with Examples

The lastDayOfYear() method of a TemporalAdjusters class is used to return the “last day of the year” TemporalAdjuster object, which returns a new Date object set to the last day of the year.

Syntax:

public static TemporalAdjuster lastDayOfYear()

Parameters: This method accepts nothing.

Return value: This method returns the last day of the year adjuster, not null.

Below programs illustrate the TemporalAdjusters.lastDayOfYear() method:
Program 1:




// Java program to demonstrate
// TemporalAdjusters.lastDayOfYear()
  
import java.time.LocalDate;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get TemporalAdjuster with last day
        // of the year adjuster
        TemporalAdjuster temporalAdjuster
            = TemporalAdjusters.lastDayOfYear();
  
        // using adjuster for local date time
        LocalDate localDate
            = LocalDate.of(2023, 10, 11);
        LocalDate lastDayOfYear
            = localDate.with(temporalAdjuster);
  
        // print
        System.out.println("last day of the "
                           + "year for localdate "
                           + localDate + ": "
                           + lastDayOfYear);
    }
}


Output:

last day of the year for localdate 2023-10-11: 2023-12-31

Program 2:




// Java program to demonstrate
// TemporalAdjusters.lastDayOfYear() method
  
import java.time.LocalDate;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get TemporalAdjuster with last day
        // of  year adjuster
        TemporalAdjuster temporalAdjuster
            = TemporalAdjusters.lastDayOfYear();
  
        // using adjuster for local date time
        LocalDate localDate
            = LocalDate.of(2099, 12, 29);
        LocalDate lastDayOfYear
            = localDate.with(temporalAdjuster);
  
        // print
        System.out.println("last day of  "
                           + "year for localdate "
                           + localDate + ": "
                           + lastDayOfYear);
    }
}


Output:

last day of  year for localdate 2099-12-29: 2099-12-31

References: https://docs.oracle.com/javase/10/docs/api/java/time/format/TemporalAdjusters.html

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6981 POSTS0 COMMENTS
Umr Jansen
6973 POSTS0 COMMENTS