Skip to main content
Version: Java (Groovy)

year

year returns the year for a date-time in the specified time zone.

Syntax

year(instant, timeZone)
year(dateTime)

Parameters

ParameterTypeDescription
instantInstant

The date-time from which to return the year.

timeZoneZoneId

The time zone.

dateTimeZonedDateTime

The date-time from which to return the year.

Returns

Returns an int value of the year for a date-time.

Examples

datetime = parseInstant("2021-06-22T08:00:00 ET")

year = year(datetime, timeZone("ET"))
println year