Saturday, October 18, 2025
HomeLanguagesJavaTemporalAdjusters firstDayOfYear() method in Java with Examples

TemporalAdjusters firstDayOfYear() method in Java with Examples

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

Syntax:

public static TemporalAdjuster firstDayOfYear()

Parameters: This method accepts nothing.

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

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




// Java program to demonstrate
// TemporalAdjusters.firstDayOfYear()
  
import java.time.LocalDate;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get TemporalAdjuster with first day
        // of the year adjuster
        TemporalAdjuster temporalAdjuster
            = TemporalAdjusters.firstDayOfYear();
  
        // using adjuster for local date-time
        LocalDate localDate
            = LocalDate.of(2012, 05, 31);
        LocalDate firstDayOfYear
            = localDate.with(temporalAdjuster);
  
        // print
        System.out.println("First day of the "
                           + "year for localdate "
                           + localDate + ": "
                           + firstDayOfYear);
    }
}


Output:

First day of the year for localdate 2012-05-31: 2012-01-01

Program 2:




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


Output:

First day of the year for localdate 2000-12-21: 2000-01-01

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

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS