Friday, June 12, 2026
HomeLanguagesJavaMonth firstDayOfYear() method in Java

Month firstDayOfYear() method in Java

The firstDayOfYear() is a built-in method of the Month ENUM which is used to get the day of year corresponding to the first day of this month.

Syntax:

public int firstDayOfYear(boolean leapYear)

Parameters: This method accepts a single parameter leapYear, which is a boolean flag variable indicating whether this Year is a leap year or not.

Return Value: This method returns the day-of-year corresponding to the first day of this month.

Below programs illustrate the above method:

Program 1:




import java.time.*;
import java.time.Month;
import java.time.temporal.Temporal;
  
class DayOfWeekExample {
    public static void main(String[] args)
    {
        // Set the month to february
        Month month = Month.of(2);
  
        // Get corresponding day-of-year of the
        // first day of february in a non-leap year
        System.out.println(month.firstDayOfYear(false));
    }
}


Output:

32

Program 2:




import java.time.*;
import java.time.Month;
import java.time.temporal.Temporal;
  
class DayOfWeekExample {
    public static void main(String[] args)
    {
        // Set the month to february
        Month month = Month.of(3);
  
        // Get corresponding day-of-year of the
        // first day of March in a leap year
        System.out.println(month.firstDayOfYear(true));
    }
}


Output:

61

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Month.html#firstDayOfYear-boolean-

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS