YearMonth getYear() example

Description

YearMonth getYear() gets the year field.

Syntax

getYear has the following syntax.


public int getYear()

Example

The following example shows how to use getYear.


import java.time.YearMonth;
//from w  w  w  .  j  a va2  s.c o  m
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    int m = y.getYear();
    System.out.println(m);

  }
}

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