Home » Java DayOfWeek enum

Java DayOfWeek enum

by Online Tutorials Library

Java DayOfWeek enum

In Java the DayOfWeek is an enum representing the 7 days of the week. In addition with the textual enum name, every day-of-week has an int value.

Java DayOfWeek enum Declaration

Let’s see the declaration of java.time.DayOfWeek.

Enum Constants

Constants Description
SUNDAY The singleton instance for the day-of-week of Sunday.
MONDAY The singleton instance for the day-of-week of Monday.
TUESDAY The singleton instance for the day-of-week of Tuesday.
WEDNESDAY The singleton instance for the day-of-week of Wednesday.
THURSDAY The singleton instance for the day-of-week of Thursday.
FRIDAY The singleton instance for the day-of-week of Friday.
SATURDAY The singleton instance for the day-of-week of Saturday.

Methods of Java DayOfWeek

Method Description
int get(TemporalField field) It is used to get the value of the specified field from this day-of-week as an int.
boolean isSupported(TemporalField field) It is used to check if the specified field is supported.
DayOfWeek minus(long days) It is used to return the day-of-week that is the specified number of days before this one.
DayOfWeek plus(long days) It is used to return the day-of-week that is the specified number of days after this one.
static DayOfWeek of(int dayOfWeek) It is used to obtain an instance of DayOfWeek from an int value.
static DayOfWeek[] values() It is used to return an array containing the constants of this enum type, in the order they are declared.
Temporal adjustInto(Temporal temporal) It adjusts the specified temporal object to have this day-of-week.
long getLong(TemporalField field) It gets the value of the specified field from this day-of-week as a long.
String getDisplayName(TextStyle style, Locale locale) It gets the textual representation, such as ‘Mon’ or ‘Friday’.
int getValue() It gets the day-of-week int value.
R query(TemporalQuery query) It queries this day-of-week using the specified query.
ValueRange range(TemporalField field) It gets the range of valid values for the specified field.
static DayOfWeek valueOf(String name) It returns the enum constant of this type with the specified name.

Methods inherited from class java.lang.Enum

  1. clone
  2. compareTo
  3. equals
  4. finalize
  5. getDeclaringClass
  6. hashCode
  7. name
  8. ordinal
  9. toString
  10. valueOf

Java DayOfWeek Example: get()

DayOfWeekExample1.java

Test it Now

Output:

3  

Java DayOfWeek Example: of()

DayOfWeekExample2.java

Test it Now

Output:

FRIDAY  4  5  

Java DayOfWeek Example: plus()

DayOfWeekExample3.java

Test it Now

Output:

2  5  

Java DayOfWeek Example: minus()

DayOfWeekExample4.java

Test it Now

Output:

2  6  

Java DayOfWeek Example: getValue()

DayOfWeekExample5.java

Test it Now

Output:

Day of the Week on 13th September 2021 - MONDAY  Int Value of MONDAY - 1  

Next TopicJava Month Enum

You may also like