JavaScript Date setUTCHours() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
UTC hour (0–23)

What You’ll Learn

setUTCHours() writes the hour (0–23) on a Date in UTC, with optional minutes, seconds, and milliseconds. This guide covers syntax, ISO scheduling, overflow, and comparisons with local setHours().

01

Syntax

setUTCHours(h)

02

24h UTC

0 – 23

03

Overload

h, m, s, ms

04

+ hours

getUTCHours

05

Overflow

Rolls days

06

Returns

Epoch ms

Introduction

Global events, cron jobs, and ISO timestamps often schedule by UTC clock time. After reading the UTC hour with getUTCHours(), setUTCHours() writes it back without local timezone offsets.

Like setHours(), it mutates the Date and returns epoch milliseconds. Use UTC getters and setters together—do not mix local setHours with UTC getUTCHours in one step.

Understanding the setUTCHours() Method

Date.prototype.setUTCHours(hour [, minute [, second [, millisecond]]]) accepts a 24-hour UTC hour and up to three optional sub-hour fields. When you pass only the hour, UTC minutes and seconds stay the same unless overflow normalization rolls the UTC calendar day.

Verify results with toISOString() or UTC getters. Hour 15 is 3:00 PM UTC in 24-hour time.

💡
Beginner Tip

To schedule at exactly 15:00:00.000 UTC: date.setUTCHours(15, 0, 0, 0). To add two UTC hours: date.setUTCHours(date.getUTCHours() + 2).

📝 Syntax

JavaScript
dateObj.setUTCHours(hour)
dateObj.setUTCHours(hour, minute)
dateObj.setUTCHours(hour, minute, second)
dateObj.setUTCHours(hour, minute, second, millisecond)

Parameters

  • hour — Integer 0–23 in UTC 24-hour time (overflow normalizes).
  • minute (optional) — 0–59 UTC.
  • second (optional) — 0–59 UTC.
  • millisecond (optional) — 0–999 UTC.

Return value

  • Updated epoch milliseconds after the change.
  • NaN if the Date was invalid before the call.

⚡ Quick Reference

GoalCode
Set UTC hour onlydate.setUTCHours(10)
Snap to 15:00:00.000 UTCdate.setUTCHours(15, 0, 0, 0)
Add 2 UTC hoursdate.setUTCHours(date.getUTCHours() + 2)
Read UTC hour after setdate.getUTCHours()
Local hour setterdate.setHours(15)
Verify ISO outputdate.toISOString()

📋 setUTCHours() vs Similar Methods

Pick the setter that matches your timezone rules.

setUTCHours()
UTC 0–23

UTC hour

getUTCHours()
read

Getter pair

setHours()
local 0–23

Local setter

setUTCMinutes()
UTC min

Minute setter

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Examples use Date.UTC() for predictable UTC times.

📚 Getting Started

Change only the UTC hour while keeping minutes and seconds.

Example 1 — Set the UTC Hour to 10 (Keep Minutes and Seconds)

Start at 12:30:45 UTC and move the hour hand to 10.

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

Passing one argument updates only the UTC hour. The trailing Z in ISO strings confirms UTC.

📈 Practical Patterns

Exact UTC snaps, relative hours, return values, and overflow.

Example 2 — Schedule at 15:00:00.000 UTC

Use the four-argument overload to zero out sub-minute UTC fields.

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

Hour 15 is 3:00 PM UTC. Setting minutes, seconds, and ms to 0 removes leftover sub-minute precision.

Example 3 — Add Two UTC Hours

Shift a UTC deadline forward by two hours.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 22, 30, 0));
date.setUTCHours(date.getUTCHours() + 2);

console.log(date.getUTCHours());   // 0
console.log(date.getUTCDate());    // 2
Try It Yourself

How It Works

22:30 UTC + 2 hours crosses midnight into 00:30 UTC on the next calendar day. Use getUTCHours(), not getHours().

Example 4 — Use the Return Value (Epoch Milliseconds)

setUTCHours returns the updated timestamp—not the Date object.

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

console.log("Type:", typeof ms);                    // "number"
console.log("Matches getTime():", ms === date.getTime()); // true
Try It Yourself

How It Works

Do not chain .setUTCMinutes() on the numeric return value. Call each setter on the same date variable.

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

Passing 25 rolls into 01:xx UTC on the next 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
Try It Yourself

How It Works

Overflow normalizes instead of clamping to 0–23. That helps when adding hours but can surprise if you expected rejection.

🚀 Common Use Cases

  • Global events — snap to setUTCHours(15, 0, 0, 0) for 3 PM UTC.
  • Server cron — schedule jobs on UTC wall clock, not local server TZ.
  • ISO APIs — align parsed timestamps to UTC hour boundaries.
  • Relative UTC shifts — postpone with getUTCHours() + N.
  • Log bucketing — group entries by UTC hour for global dashboards.
  • Clone + mutate — copy a Date before changing UTC hours.

🧠 How setUTCHours() Updates the UTC Clock

1

Read UTC time

Engine loads current UTC date and time fields.

UTC
2

Apply new hour

Hour and optional minute/second/ms replace old UTC values.

setUTCHours
3

Normalize overflow

Out-of-range values roll into adjacent UTC hours or days.

Normalize
4

Mutate & return ms

Date updates in place; epoch milliseconds are returned.

📝 Notes

  • setUTCHours() uses 24-hour UTC time (0 = midnight UTC, 12 = noon UTC).
  • Mutates the original Date—clone with new Date(date) when needed.
  • Returns epoch ms, not the Date—no fluent chaining on the return value.
  • Overflow normalizes (hour 25 → next UTC day hour 1).
  • For real timezone conversion, use Intl or libraries—not naive offset math on getters.
  • Use setHours for local user-facing clocks; setUTCHours for ISO/server rules.

Browser & Runtime Support

Date.prototype.setUTCHours() has been available since ES1. It works in every browser and Node.js.

Baseline · ES1

Date.prototype.setUTCHours()

Supported in Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions. No polyfill required.

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 everywhere. Remember 24-hour UTC time, mutation, and the four-argument snap pattern.

Conclusion

setUTCHours() writes the UTC hour (and optionally minutes, seconds, and milliseconds) on a JavaScript Date. Use it for ISO-aligned scheduling; use setHours() for local wall clocks.

Next, learn setUTCMilliseconds() to change the UTC sub-second fraction, or review getUTCHours() for reading the UTC hour.

💡 Best Practices

✅ Do

  • Use setUTCHours(15, 0, 0, 0) for exact UTC wall-clock times
  • Think in 24-hour UTC values (15 = 3 PM UTC)
  • Verify with toISOString() after changes
  • Pair with getUTCHours() for relative shifts
  • Clone before mutating shared Date instances

❌ Don’t

  • Mix setUTCHours with getHours() in one calculation
  • Chain setters on the numeric return value
  • Assume values clamp at 23 (overflow rolls days)
  • Use local setters for UTC cron rules
  • Forget midnight UTC is hour 0, not 24

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.setUTCHours()

Your foundation for UTC hour writes in JavaScript.

5
Core concepts
🌐 02

0–23 UTC

24-hour.

Range
📈 03

4 args

h, m, s, ms.

Overload
04

+ hours

getUTCHours.

Pattern
🔄 05

Mutates

In place.

Behavior

❓ Frequently Asked Questions

It sets the hour (0–23) of a Date object in UTC. Optional arguments can also set UTC minutes, seconds, and milliseconds. The Date mutates in place and returns updated epoch milliseconds.
setHours() changes the local clock hour. setUTCHours() changes the UTC clock hour. Use the one that matches your timezone rules.
getUTCHours() reads the current UTC hour. setUTCHours(h) writes a new UTC hour. They are the read/write pair for 24-hour UTC time.
24-hour format. Midnight UTC is 0, noon UTC is 12, and 11 PM UTC is 23.
JavaScript normalizes overflow into the next UTC calendar day. setUTCHours(25) rolls into 01:xx UTC on the following day.
No. It returns a number (epoch milliseconds). Call each setter on the same Date variable—do not chain on the return value.
Did you know?

setUTCHours(15, 0, 0, 0) sets 3:00 PM UTC exactly—the same instant may show a different local hour in getHours() depending on your timezone offset.

Continue to 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.

6 people found this page helpful