WeekFields of() method in Java with Examples Last Updated : 29 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Return value: This method returns the week-definition, not null. Exception: This method throws IllegalArgumentException if the minimal day's value is less than one or greater than 7. Below program illustrate the WeekFields.of(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek) method: Program 1: 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: WeekFields[SUNDAY, 1] References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html Comment More infoAdvertise with us Next Article WeekFields toString() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java.time.temporal package Java-WeekFields Practice Tags : Java Similar Reads WeekFields toString() method in Java with Examples The toString() method of WeekFields class is used to return string representation of this WeekFields object. Syntax: public String toString() Parameters: This method accepts nothing. Return value: This method returns string representation of this WeekFields. Below programs illustrate the WeekFields. 1 min read Period of() method in Java with Examples The of() method of Period Class is used to obtain a period from given number of Years, Months, and Days as parameters. These parameters are accepted in the form of integers. This method returns a Period with the given number of years, months, and days. Syntax: public static Period of( int numberOfYe 2 min read Period ofWeeks() method in Java with Examples The ofWeeks() method of Period Class is used to obtain a period from given number of Weeks as parameter. This parameter is accepted in the form of integer. This method returns a Period with the given number of weeks. Syntax: public static Period ofWeeks(int numberOfWeeks) Parameters: This method acc 2 min read WeekFields dayOfWeek() method in Java with Examples The dayOfWeek() method of WeekFields class is used to return a field to access the day of the week based on this WeekFields. For example, if the first day-of-week is Monday, then that will have the value 1, with other days ranging from Tuesday as 2 to Sunday as 7. Syntax: public TemporalField dayOfW 2 min read WeekFields weekOfYear() method in Java with Examples The weekOfYear() method of WeekFields class is used to return a field to access the week of year based on this WeekFields. Example: if the 1st day of the year is a Monday, week one starts on the 1st and there is no week zero if the 2nd day of the year is a Monday, week one starts on the 2nd and the 2 min read WeekFields weekOfMonth() method in Java with Examples The weekOfMonth() method of WeekFields class is used to return the field to access the week of month based on this WeekFields. For example: if the 1st day of the month is a Monday, week one starts on the 1st and there is no week zero if the 2nd day of the month is a Monday, week one starts on the 2n 2 min read Like