Month firstDayOfYear() method in Java
Last Updated :
22 Mar, 2019
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)
{
Month month = Month.of( 2 );
System.out.println(month.firstDayOfYear( false ));
}
}
|
Program 2:
import java.time.*;
import java.time.Month;
import java.time.temporal.Temporal;
class DayOfWeekExample {
public static void main(String[] args)
{
Month month = Month.of( 3 );
System.out.println(month.firstDayOfYear( true ));
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Month.html#firstDayOfYear-boolean-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...