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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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));
    }
}

chevron_right


Output:

32

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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));
    }
}

chevron_right


Output:

61

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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.