Temporal.ZonedDateTime.prototype.hoursInDay
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The hoursInDay
accessor property of Temporal.ZonedDateTime
instances returns a positive integer representing the number of hours in the day of this date in the time zone. It may be more or less than 24 in the case of offset changes such as daylight saving time.
Because ZonedDateTime
is the only class that's time zone-aware, and hours in a day can only change by offset changes, all other classes assume 24-hour days.
The set accessor of hoursInDay
is undefined
. You cannot change this property directly.
Examples
Using hoursInDay
const dt = Temporal.ZonedDateTime.from(
"2024-03-10T01:58:00-05:00[America/New_York]",
);
console.log(dt.hoursInDay); // 23; this is the day of transition into DST
const dt2 = Temporal.ZonedDateTime.from(
"2024-11-03T01:58:00-04:00[America/New_York]",
);
console.log(dt2.hoursInDay); // 25; this is the day of transition out of DST
const dt3 = Temporal.ZonedDateTime.from(
"2024-11-04T01:58:00-05:00[America/New_York]",
);
console.log(dt3.hoursInDay); // 24
Specifications
Specification |
---|
Temporal proposal # sec-get-temporal.zoneddatetime.prototype.hoursinday |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
hoursInDay |
Legend
Tip: you can click/tap on a cell for more information.
- No support
- No support
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- User must explicitly enable this feature.
See also
Temporal.ZonedDateTime
Temporal.ZonedDateTime.prototype.with()
Temporal.ZonedDateTime.prototype.add()
Temporal.ZonedDateTime.prototype.subtract()
Temporal.ZonedDateTime.prototype.hour
Temporal.ZonedDateTime.prototype.dayOfYear
Temporal.ZonedDateTime.prototype.daysInMonth
Temporal.ZonedDateTime.prototype.daysInWeek