Java Date Time - OffsetDateTime getYear() example








OffsetDateTime getYear() gets the year field. This method returns the primitive int value for the year.

Syntax

getYear has the following syntax.

public int getYear()

Example

The following example shows how to use getYear.

import java.time.OffsetDateTime;

public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    int l = o.getYear();
    System.out.println(l);
  }
}

The code above generates the following result.