Java Date Time Java Java API
java.time.OffsetDateTime
public int getYear()
Returns the year field from this OffsetDateTime instance.
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class GetYearExample { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2012, 10, 3, 11, 43, 30, 1000), ZoneOffset.ofHours(-5)); int year = d.getYear(); System.out.println(year); }}
2012