The of() method of WeekFields class helps us to obtain an instance of WeekFields.
There are two types of of() methods based on parameters passed to it.
- of(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek): This method helps us to an instance of WeekFields from the first day-of-week and minimal days.WeekFields instances are singletons; for each unique combination of firstDayOfWeek and minimalDaysInFirstWeek the same instance will be returned.
Syntax:
public static WeekFields of(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek)Parameters: This method accepts two parameters:- firstDayOfWeek which is the first day of the week. It should not be null
- minimalDaysInFirstWeek which is the minimal number of days in the first week, from 1 to 7.
Java // Java program to demonstrate // WeekFields.of(DayOfWeek, int) method import java.time.DayOfWeek; import java.time.temporal.WeekFields; public class GFG { public static void main(String[] args) { // create WeekFields WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1); // print results System.out.println(weekFields); } }
Output:WeekFields[MONDAY, 1]
- of(Locale locale): This method help us to get an instance of WeekFields appropriate for a locale.
Syntax:
public static WeekFields of(Locale locale)
Parameters: This method accepts locale as a parameter which is the locale to use. It should not be null. Return value: This method returns the week-definition, not null. Below program illustrate the WeekFields.of(long min, long maxSmallest, long maxLargest) method: Program 2:Java // Java program to demonstrate // of(Locale locale) method import java.time.temporal.WeekFields; import java.util.Locale; public class GFG { public static void main(String[] args) { Locale locale = new Locale("EN", "US"); // create WeekFields WeekFields weekFields = WeekFields.of(locale); // print results System.out.println(weekFields); } }
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.htmlWeekFields[SUNDAY, 1]