Skip to main content
Version: Java (Groovy)

monthOfYear

monthOfYear returns the 1-based value for the month of the year for a specified date-time.

Syntax

monthOfYear(instant, timeZone)
monthOfYear(dateTime)

Parameters

ParameterTypeDescription
instantInstant

The date-time from which to return the number of months.

timeZoneZoneId

The time zone.

dateTimeZonedDateTime

The date-time from which to return the number of months.

Returns

Returns an int value representing the month of the year.

Examples

datetime = parseInstant("2022-01-01T12:34:56 ET")

month = monthOfYear(datetime, timeZone("ET"))

println month