The get() method of java.time.DayOfWeek is an in-built function in Java which takes a TemporalField as parameter and gets the value of the specified field from this day-of-week as an int. The TemporalField is a field of date-time, such as month-of-year or hour-of-minute. Date and time is expressed using such fields. If the field is DAY_OF_WEEK then the value of the day-of-week, from 1 to 7, will be returned. All other ChronoField instances will throw an UnsupportedTemporalTypeException. The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
public int get(TemporalField field);
int val = DayOfWeekObject.get(TemporalField field);
Parameters: This method takes field as parameter where:
Parameters: This method does not accepts any parameters.
Return Value: The function returns int value of the day of the week, e.g, 1 for Monday, 2 for Tuesday and so on.
Below programs illustrate the above method:
Day of the Week on 1947-08-15 - FRIDAY Int Value of FRIDAY - 5
Day of the Week on 2015-07-13 - MONDAY Int Value of MONDAY - 1
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.