Java Date Time - DayOfWeek of(int dayOfWeek) example








DayOfWeek of(int dayOfWeek) returns an instance of DayOfWeek from an int value.

DayOfWeek is an enum representing the 7 days of the week.

This factory allows the enum to be obtained from the int value.

The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).

Syntax

of has the following syntax.

public static DayOfWeek of(int dayOfWeek)

Example

The following example shows how to use of.

import java.time.DayOfWeek;
/*w  w w.  j av a2s . c  o m*/
public class Main {
  public static void main(String[] args) {
    DayOfWeek dayOfWeek = DayOfWeek.of(1);
    System.out.println(dayOfWeek.name());
    System.out.println(dayOfWeek.getValue());
    System.out.println(dayOfWeek.ordinal());
  }
}

The code above generates the following result.