Month from(TemporalAccessor temporal) example

Description

Month from(TemporalAccessor temporal) creates an instance of Month from a temporal object.

Syntax

from has the following syntax.


public static Month from(TemporalAccessor temporal)

Example

The following example shows how to use from.


import java.time.LocalDate;
import java.time.Month;
/*from   w  w  w .ja v  a  2s  . c o m*/
public class Main {
  public static void main(String[] args) {
    Month m = Month.from(LocalDate.now());
    System.out.println(m.getValue());
    System.out.println(m.name());
    System.out.println(m.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