Date UTC methods (getUTCHours, setUTCMonth…)
Fifteen methods that duplicate the local family with UTC as the basis. Reach for these whenever the answer must not depend on where the code happens to run.
Demo
The pair is [getUTCHours(), getHours()]. The first number is the same for every reader of this page. The second is whatever YOUR timezone makes of that instant — if the two numbers differ, that gap is your UTC offset, and if they happen to match you are reading this from UTC. The third case is the one that causes dated bugs: at 23:00 UTC a reader east of Greenwich is already on the following DAY, so getDate and getUTCDate disagree about the date entirely, not just the hour.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| value | number | no (none) | For the setUTC family only. Same rollover behaviour as the local setters — an out-of-range value adjusts the larger components. |
Return value
number — The same components as the local family, computed in UTC — so the answer is identical everywhere in the world for a given timestamp.
Common patterns
const key = `${d.getUTCFullYear()}-${d.getUTCMonth() + 1}-${d.getUTCDate()}`;
const d = new Date(Date.UTC(2026, 2, 15));
d.toLocaleString(undefined, {timeZone: 'UTC'});
Examples
Pitfalls
`${d.getUTCMonth()}/${d.getUTCDate()}`
`${d.getUTCMonth() + 1}/${d.getUTCDate()}`
d.getFullYear() + "-" + d.getUTCMonth()
d.getUTCFullYear() + "-" + d.getUTCMonth()
new Date(Date.UTC(2026, 2, 15, 8))
({local: '2026-03-15T09:00', tz: 'Europe/Berlin'})
new Date().getUTCTimezoneOffset()
0When to use
- Server-side code, where the machine timezone is an accident
- Grouping or bucketing by day across users in different zones
- Anything stored, compared or transmitted
- Reproducible tests that must not depend on the runner timezone
- Showing a time to a person → the local getters, or Intl with their timezone
- Wall-clock intent that must survive DST → store the zone name too
- Formatting → toISOString or toLocaleString
Notes
FAQ
On a server, close to it — the machine timezone is usually incidental and letting it leak into stored data causes bugs that only appear after a deployment moves. In the browser, use the local family when showing a time to the person sitting there, and UTC for anything you send or store.