Java Date Time - DayOfWeek from(TemporalAccessor temporal) example








DayOfWeek from(TemporalAccessor temporal) gets an instance of DayOfWeek from a temporal object. This obtains a day-of-week based on the specified temporal.

Syntax

from has the following syntax.

public static DayOfWeek from(TemporalAccessor temporal)

Example

The following example shows how to use from.

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
//from   w  w w .java 2  s. c om
public class Main {
  public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, Month.JUNE, 21);
    DayOfWeek dayOfWeek = DayOfWeek.from(localDate);
    System.out.println(dayOfWeek.name());
    System.out.println(dayOfWeek.getValue());
    System.out.println(dayOfWeek.ordinal());
  }
}

The code above generates the following result.