hourOfDay
hourOfDay returns an int representing the hour of the input date-time. Hours are from 0-23, with times between midnight and 1AM on a given day returning the hour 0.
Note
On days when daylight savings time events occur, results may be different from what is expected based upon the local time. For example, on daylight savings time change days, 9:30AM may be earlier or later in the day based upon if the daylight savings time adjustment is forwards or backwards.
Syntax
hourOfDay(instant, timeZone, localTime)
hourOfDay(dateTime, localTime)
hourOfDay(localTime)
Parameters
| Parameter | Type | Description |
|---|---|---|
| instant | Instant | The time for which to find the hour of the day. |
| timeZone | TimeZone | s The time zone to use when interpreting the date-time. |
| dateTime | ZonedDateTime | The zoned date-time for which to find the hour of the day. |
| localTime | boolean | Set this parameter to
|
Returns
Returns a 0-based int value of the hour of the day.
Examples
datetime = parseInstant("2024-02-29T01:23:45 ET")
datetime_zoned = toZonedDateTime(datetime, timeZone("MT"))
hour = hourOfDay(datetime, timeZone("ET"), false)
hour_zoned = hourOfDay(datetime_zoned, false)
println hour
println hour_zoned