WeekFields dayOfWeek() method in Java with Examples Last Updated : 29 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 dayOfWeek() Parameters: This method accepts nothing. Return value: This method returns a field providing access to the day-of-week with localized numbering, not null. Below programs illustrate the WeekFields.dayOfWeek() method: Program 1: Java // Java program to demonstrate // WeekFields.dayOfWeek() method import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.TemporalField; import java.time.temporal.WeekFields; public class GFG { public static void main(String[] args) { // create WeekFields WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1); // apply dayOfWeek() TemporalField dayOfWeek = weekFields.dayOfWeek(); // create a LocalDate LocalDate day = LocalDate.of(2021, 12, 21); // get day of week for localdate int dow = day.get(dayOfWeek); // print results System.out.println("day of week for " + day + " :" + dow); } } Output: day of week for 2021-12-21 :2 Program 2: Java // Java program to demonstrate // WeekFields.dayOfWeek() method import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.TemporalField; import java.time.temporal.WeekFields; public class GFG { public static void main(String[] args) { // create WeekFields WeekFields weekFields = WeekFields.of(DayOfWeek.SUNDAY, 1); // apply dayOfWeek() TemporalField dayOfWeek = weekFields.dayOfWeek(); // create a LocalDate LocalDate day = LocalDate.of(2018, 05, 31); // get day of week for localdate int dow = day.get(dayOfWeek); // print results System.out.println("day of week for " + day + " :" + dow); } } Output: day of week for 2018-05-31 :5 References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#dayOfWeek() Comment More infoAdvertise with us Next Article DayOfWeek plus() 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 DayOfWeek plus() method in Java with Examples The plus() method of java.time.DayOfWeek is an in-built function in Java which takes a long integer as parameter and returns an instance of DayOfWeek after advancing some days forward or backward as specified by the passed parameter. The calculation rolls around the end of the week from Sunday to Mo 2 min read DayOfWeek of() method in Java with Examples The of() method of java.time.DayOfWeek is an in-built function in Java which returns an instance of DayOfWeek from an int value. The int value ranges between 1 (Monday) to 7 (Sunday). Method Declaration: public static DayOfWeek of(int dayOfWeek) Syntax: DayOfWeek dayOfWeekObject = DayOfWeek.of(int d 2 min read DayOfWeek minus() method in Java with Examples The minus() method of java.time.DayOfWeek is an in-built function in Java which takes a long integer as parameter and returns an instance of DayOfWeek after advancing some days backward or forward as specified by the passed parameter. The calculation rolls around the end of the week from Monday to S 2 min read DayOfWeek values() method in Java with Examples The values() method of java.time.DayOfWeek is an in-built function in Java which returns an array containing the days of the week, e.g. MONDAY, TUESDAY and so on, in the order they are declared. Method Declaration: public static DayOfWeek[] values() Syntax: DayOfWeek week[] = DayOfWeek.values() Para 2 min read DayOfWeek valueOf() method in Java with Examples The valueOf() method of java.time.DayOfWeek is an in-built function in Java which takes a string and returns an instance of DayOfWeek corresponding to the string. The string must match exactly to the identifier used to declare a day-of-week constant in this type. Extraneous white space characters ar 1 min read WeekFields of() method in Java with Examples 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 d 2 min read Like