JavaScript Date getUTCHours() Method

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

What You’ll Learn

getUTCHours() returns the hour (0–23) from a Date object in UTC. This guide covers syntax, five examples, comparisons with local getters, and safe UTC time patterns.

01

Syntax

date.getUTCHours()

02

Range

0 – 23

03

UTC

24-hour

04

vs getHours

Can differ

05

Format

HH:MM UTC

06

Validate

Invalid → NaN

Introduction

Servers, logs, and APIs often work in UTC. The JavaScript Date object stores one instant internally; getUTCHours() reads the hour component according to UTC, not the user’s local timezone.

If you need the hour for a greeting or clock in the user’s locale, use getHours(). Use getUTCHours() when your scheduling or reporting follows UTC boundaries.

Understanding the getUTCHours() Method

Date.prototype.getUTCHours() is a zero-argument instance method. It never mutates the original Date—it only reads the UTC hour as an integer from 0 (midnight UTC) to 23.

Pair it with getUTCMinutes(), getUTCSeconds(), and getUTCMilliseconds() for manual UTC time assembly, or use toISOString() when a full UTC string is enough.

💡
Beginner Tip

getUTCHours() returns 24-hour time only. Hour 14 means 2:00 PM UTC—not "2 PM" as a string.

📝 Syntax

JavaScript
dateObj.getUTCHours()

Parameters

  • None.

Return value

  • Integer 0–23 for a valid date in UTC (24-hour format).
  • NaN if dateObj is an invalid Date.

⚡ Quick Reference

GoalCode
Current UTC hournew Date().getUTCHours()
Hour from UTC partsnew Date(Date.UTC(2026, 6, 4, 14, 30)).getUTCHours() → 14
Local hourdate.getHours()
UTC minutesdate.getUTCMinutes()
Midnight UTC checkdate.getUTCHours() === 0
Valid date check!Number.isNaN(date.getTime())

📋 getUTCHours() vs Similar Methods

UTC getters mirror local getters. Pick the one that matches where your data is displayed or stored.

getUTCHours()
0–23

UTC hour

getHours()
local

Local hour

getUTCMinutes()
0–59

UTC minute

toISOString()
…T…Z

Full UTC string

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Fixed UTC times use Date.UTC or ISO strings ending in Z for predictable results.

📚 Getting Started

Read the current UTC hour from a new Date.

Example 1 — Get the Current UTC Hour

Call getUTCHours() on the current instant.

JavaScript
const now = new Date();
const utcHour = now.getUTCHours();

console.log("UTC hour:", utcHour);
Try It Yourself

How It Works

The same instant can show a different hour locally vs UTC. getUTCHours() always uses the UTC clock.

📈 Practical Patterns

Fixed times, validation, formatting, and local comparison.

Example 2 — Read the Hour from a Fixed UTC Time

Build a date at 14:30 UTC with Date.UTC.

JavaScript
const afternoonUtc = new Date(Date.UTC(2026, 6, 4, 14, 30));

console.log(afternoonUtc.getUTCHours());     // 14
console.log(afternoonUtc.getUTCMinutes());   // 30
Try It Yourself

How It Works

Date.UTC(y, m, d, h, min) creates a UTC timestamp. UTC getters read back the same hour everywhere, regardless of the user’s timezone.

Example 3 — Validate Before Calling getUTCHours()

Guard against invalid Date objects that yield NaN.

JavaScript
function safeGetUTCHours(date) {
  if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
    return null;
  }
  return date.getUTCHours();
}

console.log(safeGetUTCHours(new Date()));              // e.g. 2
console.log(safeGetUTCHours(new Date("not-a-date")));  // null
Try It Yourself

How It Works

getTime() returns NaN on invalid dates. Checking first prevents broken comparisons like hour < 12 when hour is NaN.

Example 4 — Format a UTC HH:MM String

Combine UTC hour and minute getters with zero-padding.

JavaScript
function formatUtcTime(date) {
  const hours = String(date.getUTCHours()).padStart(2, "0");
  const minutes = String(date.getUTCMinutes()).padStart(2, "0");
  return hours + ":" + minutes;
}

const sample = new Date(Date.UTC(2026, 6, 4, 9, 5));
console.log(formatUtcTime(sample)); // 09:05
Try It Yourself

How It Works

padStart(2, "0") keeps single-digit hours and minutes readable. For production, toISOString() or Intl.DateTimeFormat with timeZone: "UTC" is often simpler.

Example 5 — Compare getHours() and getUTCHours()

The same instant can show different hours in local time vs UTC.

JavaScript
const date = new Date("2026-06-15T20:30:00.000Z");

console.log("UTC hour:", date.getUTCHours());   // 20
console.log("Local hour:", date.getHours());    // depends on timezone
Try It Yourself

How It Works

At 20:30 UTC on June 15, it is 02:00 on June 16 in UTC+5:30. getUTCHours() stays 20; getHours() becomes 2. Use UTC getters when cron or batch rules follow UTC.

🚀 Common Use Cases

  • UTC cron jobs — run tasks at a specific UTC hour.
  • Log timestamps — display UTC hour in debug panels.
  • Global dashboards — bucket traffic by UTC hour.
  • API windows — allow requests only during UTC business hours.
  • Manual formatting — build HH:MM with UTC getters.
  • Midnight UTC checks — detect daily rollover at hour 0.

🧠 How getUTCHours() Resolves the Hour

1

Internal instant

The Date stores milliseconds since Unix epoch (UTC).

Storage
2

UTC projection

Engine reads time fields in UTC, not local time.

UTC
3

Extract hour

UTC hour 0–23 is returned as an integer.

getUTCHours
4

Use in logic

Format, compare, or schedule against UTC hour boundaries.

📝 Notes

  • getUTCHours() is UTC; use getHours() for local UI clocks.
  • Returns 24-hour integers only—not AM/PM strings.
  • Midnight UTC is 0, not 24.
  • Invalid dates propagate NaN—validate with Number.isNaN(date.getTime()).
  • Do not use hour getters alone to measure elapsed time—use getTime() subtraction.
  • For full UTC strings, toISOString() is often simpler than manual getters.

Browser & Runtime Support

Date.prototype.getUTCHours() has been available since the first JavaScript Date implementation (ES1). It works in every browser and Node.js.

Baseline · ES1

Date.prototype.getUTCHours()

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.getUTCHours() Excellent

Bottom line: Safe everywhere. Pair UTC getters together and pick UTC vs local based on your scheduling rules.

Conclusion

getUTCHours() reads the hour (0–23) from a JavaScript Date in UTC. Use it for global scheduling and UTC time assembly; use local getters or locale formatters when showing clocks to end users.

Next, learn getUTCMilliseconds() for the UTC sub-second fraction, or review getHours() for local hour reads.

💡 Best Practices

✅ Do

  • Validate dates before calling getUTCHours()
  • Use UTC getters together for UTC formatting
  • Prefer Date.UTC in tests for stable fixtures
  • Document whether rules follow UTC or local time
  • Use getTime() for elapsed duration

❌ Don’t

  • Assume getHours() equals getUTCHours()
  • Expect AM/PM strings from the getter
  • Use hour subtraction for elapsed timers
  • Mix local and UTC getters in one label
  • Ignore NaN from bad date parses

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.getUTCHours()

Your foundation for UTC hour reads in JavaScript.

5
Core concepts
🔢 02

0–23

24-hour UTC.

Range
🌐 03

UTC

Not local.

Timezone
04

HH:MM

Pad digits.

Format
05

Not elapsed

Use getTime().

Pitfall

❓ Frequently Asked Questions

An integer from 0 to 23 representing the hour in the Date object's UTC timezone. It uses 24-hour time: midnight UTC is 0, noon UTC is 12, and 11 PM UTC is 23.
getUTCHours() uses UTC rules. getHours() uses local timezone rules. They can differ when your offset shifts the hour or calendar day.
No. It always returns 24-hour format (0–23). Convert to 12-hour display yourself or use Intl.DateTimeFormat with timeZone: 'UTC'.
NaN. Validate with Number.isNaN(date.getTime()) before using the result in conditionals or UI.
Midnight UTC is 0. There is no hour 24—23 is the last hour of the UTC day.
For sending timestamps to servers, toISOString() is usually enough. Use getUTCHours() when you assemble UTC time parts manually or teach how UTC getters work.
Did you know?

At 2026-06-15T20:30:00.000Z, getUTCHours() is always 20, but getHours() can be 2 in UTC+5:30—the same instant, different hour on the clock.

Continue to getUTCMilliseconds()

Learn how to read the millisecond fraction (0–999) within the current UTC second.

getUTCMilliseconds() 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