JavaScript Date setUTCHours() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

Date.prototype.setUTCHours() changes the hours (and optionally minutes, seconds, and milliseconds) of a Date in UTC. It mutates the date in place and returns the new epoch timestamp.

Remember
date.setUTCHours(hoursValue)
date.setUTCHours(h, min, sec, ms)

hoursValue → 0–23 (UTC 24-hour clock)
overflow   → rolls into the next UTC day
returns    → epoch milliseconds (or NaN)

setUTCHours() → UTC wall clock
setHours()    → local wall clock

Syntax

Call date.setUTCHours. Start with this line.

JavaScript
date.setUTCHours(h[, min[, sec[, ms]]])
CallWhat it does
date.setUTCHours(h[, min[, sec[, ms]]])Primary signature.
date.setUTCHours(...)Call with the arguments your case needs.

Built into JavaScript. Call setUTCHours(...) on a Date instance — no import required.

Library declarations
JavaScript
date.setUTCHours(h[, min[, sec[, ms]]])

Parameters

ParameterDescription
hoursValueRequired. UTC hour (0–23; overflow allowed)
minutesValueOptional. UTC minutes (0–59)
secondsValueOptional. UTC seconds — requires minutes too
msValueOptional. UTC ms — requires minutes and seconds

Return Value

Return ValueDescription
*The value returned by date.setUTCHours().

JavaScript Examples

Example 1 — Set the UTC Hour Only

Move the UTC hour to 10 while keeping minutes and seconds.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 12, 30, 45));
date.setUTCHours(10);

console.log(date.getUTCHours());   // 10
console.log(date.getUTCMinutes()); // 30
console.log(date.toISOString());   // "2026-03-01T10:30:45.000Z"
Try It Yourself

How It Works

  1. Build a UTC date. Date.UTC(2026, 2, 1, 12, 30, 45) is March 1, 2026 at 12:30:45 UTC (month index 2).
  2. Change only the hour. setUTCHours(10) writes hour 10 and leaves minutes/seconds alone.
  3. Read it back. getUTCHours() → 10, getUTCMinutes() → 30.
  4. Confirm ISO. The trailing Z means UTC — 10:30:45.000Z.

Example 2 — Snap to 15:00:00.000 UTC

Use four arguments to set an exact UTC wall-clock time.

JavaScript
const meeting = new Date(Date.UTC(2026, 2, 1, 9, 45, 30, 500));
meeting.setUTCHours(15, 0, 0, 0);

console.log(meeting.getUTCHours());   // 15
console.log(meeting.getUTCMinutes()); // 0
console.log(meeting.toISOString());   // "2026-03-01T15:00:00.000Z"
Try It Yourself

How It Works

  1. Start messy. The date begins at 09:45:30.500 UTC.
  2. Pass four args. Hour 15, then 0, 0, 0 for minutes, seconds, and ms.
  3. Clear leftovers. Sub-hour fields become zero — no leftover 45 minutes.
  4. Read 3 PM UTC. Hour 15 is 3:00 PM on the 24-hour UTC clock.

Example 3 — UTC Hour Overflow (setUTCHours(25))

Out-of-range hours roll into the next UTC calendar day.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 12, 30, 45));
date.setUTCHours(25);

console.log(date.getUTCHours()); // 1
console.log(date.getUTCDate());  // 2
console.log(date.toISOString()); // "2026-03-02T01:30:45.000Z"
Try It Yourself

How It Works

  1. Start March 1. The date is 12:30:45 UTC on day 1.
  2. Pass 25. 25 hours = 1 full day + 1 hour.
  3. Normalize. Day becomes 2, hour becomes 1; minutes stay 30.
  4. Use carefully. Overflow helps when adding hours, but it will not reject bad input.

Browser & Runtime Support

Date.prototype.setUTCHours() has been in JavaScript since ES1. It is Baseline and works in every modern browser and Node.js — no polyfill needed.

✓ Baseline · ES1

Date.prototype.setUTCHours()

Supported everywhere Date exists: Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions.

99% Universal API
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.setUTCHours() Excellent

Bottom line: Safe to use in any environment. Remember UTC vs local, mutation, and overflow normalization. See also the MDN setUTCHours() reference.

Frequently Asked Questions

It sets the hour (0–23) of a Date according to universal time (UTC). Optional arguments can also set UTC minutes, seconds, and milliseconds. The Date mutates in place and returns the new timestamp in milliseconds.
setHours() changes the local clock hour. setUTCHours() changes the UTC clock hour. Use the setter that matches your timezone rules—do not mix them with the opposite getters.
If you pass only the hour, the current UTC minutes, seconds, and milliseconds are kept (from getUTCMinutes, getUTCSeconds, and getUTCMilliseconds).
JavaScript normalizes overflow into the next UTC calendar day. setUTCHours(25) becomes 01:xx UTC on the following day (minutes/seconds unchanged unless you pass them).
No. It returns a number (epoch milliseconds), or NaN if the date becomes invalid. Call each setter on the same Date variable—do not chain on the return value.
Use it for ISO timestamps, server cron, and global schedules that must follow UTC wall-clock time. Prefer setHours() for user-facing local clocks.

Next: setUTCMilliseconds()

Learn how to set the UTC sub-second fraction (0–999) on a Date object.

setUTCMilliseconds() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful