WeekFields getFirstDayOfWeek() method in Java with Examples
The getFirstDayOfWeek() method of WeekFields class is used to return the first day-of-week as a DayOfWeek enum.For example, the US uses Sunday, while France uses Monday.
Syntax:
public DayOfWeek getFirstDayOfWeek()
Parameters: This method accepts nothing.
Return value: This method returns the first day-of-week, not null.
Below programs illustrate the WeekFields.getFirstDayOfWeek() method:
Program 1:
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
public class GFG {
public static void main(String[] args)
{
WeekFields weekFields
= WeekFields.of(DayOfWeek.MONDAY, 1 );
DayOfWeek firstDay
= weekFields.getFirstDayOfWeek();
System.out.println( "First Day:"
+ firstDay);
}
}
|
Program 2:
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
import java.util.Locale;
public class GFG {
public static void main(String[] args)
{
Locale locale = new Locale( "EN" , "US" );
WeekFields weekFields
= WeekFields.of(locale);
DayOfWeek firstDay
= weekFields.getFirstDayOfWeek();
System.out.println( "First Day:"
+ firstDay);
}
}
|
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#getFirstDayOfWeek()
Last Updated :
29 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...