Java Date Time - YearMonth getYear() example








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;
//w w  w  .  j a va 2s. com
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.