Year from(TemporalAccessor temporal) example

Description

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

Syntax

from has the following syntax.


public static Year from(TemporalAccessor temporal)

Example

The following example shows how to use from.


import java.time.LocalDate;
import java.time.Year;
/*from w ww  .j ava 2  s .  c  o m*/
public class Main {
  public static void main(String[] args) {
    Year y = Year.from(LocalDate.now());
    System.out.println(y);

  }
}

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