DayOfWeek of(int dayOfWeek) example

Description

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  ww  .  j av a2 s . 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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset