Skip to main content
Version: Java (Groovy)

dayOfWeek

dayOfWeek returns the integer value of the day of the week for an input date-time in the specified time zone, with 1 being Monday and 7 being Sunday.

Syntax

dayOfWeek(instant, timeZone)
dayOfWeek(dateTime)

Parameters

ParameterTypeDescription
instantInstant

The instant for which to find the day of the month.

timeZoneTimeZone

The time zone to use when interpreting the date-time.

dateTimeZonedDateTime

The zoned date-time for which to find the day of the week.

Returns

Returns a 1-based int value of the day of the week.

Examples

datetime = parseInstant("2024-02-29T01:23:45 ET")
datetime_zoned = toZonedDateTime(datetime, timeZone("MT"))

day = dayOfWeek(datetime, timeZone("ET"))
day_zoned = dayOfWeek(datetime_zoned)

println day
println day_zoned