JavaScript Date getUTCSeconds() Method

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

What You’ll Learn

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

01

Syntax

date.getUTCSeconds()

02

Range

0 – 59

03

UTC

Not local

04

vs getSeconds

Can differ

05

Format

HH:MM:SS UTC

06

Validate

Invalid → NaN

Introduction

Server logs, API timestamps, and global cron rules often reference UTC clocks. The JavaScript Date object stores one instant internally; getUTCSeconds() reads the second hand of the UTC clock—not total seconds elapsed since midnight or since 1970.

If you need seconds for a user-facing local clock, use getSeconds(). Use getUTCSeconds() when your scheduling or display follows UTC boundaries.

Understanding the getUTCSeconds() Method

Date.prototype.getUTCSeconds() is a zero-argument instance method. It never mutates the original Date—it only reads the UTC second component as an integer from 0 to 59.

Pair it with getUTCHours(), getUTCMinutes(), and getUTCMilliseconds() to assemble UTC time parts, or use toISOString() when a full UTC string is enough.

💡
Beginner Tip

For elapsed duration between two instants, subtract getTime() values and divide by 1000—do not subtract getUTCSeconds() alone.

📝 Syntax

JavaScript
dateObj.getUTCSeconds()

Parameters

  • None.

Return value

  • Integer 0–59 for a valid date in UTC.
  • NaN if dateObj is an invalid Date.

⚡ Quick Reference

GoalCode
Current UTC secondsnew Date().getUTCSeconds()
Seconds from UTC partsnew Date(Date.UTC(2026, 6, 4, 14, 30, 45)).getUTCSeconds() → 45
Local secondsdate.getSeconds()
Pad to two digitsString(date.getUTCSeconds()).padStart(2, "0")
Elapsed seconds(end.getTime() - start.getTime()) / 1000
Valid date check!Number.isNaN(date.getTime())

📋 getUTCSeconds() vs Similar Methods

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

getUTCSeconds()
0–59

UTC seconds

getSeconds()
local

Local seconds

getUTCMinutes()
0–59

UTC minutes

getTime()
epoch ms

Full instant

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 second component from a new Date.

Example 1 — Get the Current UTC Seconds

Call getUTCSeconds() on the current instant.

JavaScript
const now = new Date();
const utcSeconds = now.getUTCSeconds();

console.log("UTC seconds:", utcSeconds);
Try It Yourself

How It Works

The value updates each second and stays between 0 and 59. UTC hours, minutes, and milliseconds are separate getters.

📈 Practical Patterns

Fixed times, validation, formatting, and local comparison.

Example 2 — Read Seconds from a Fixed UTC Time

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

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

console.log(eventUtc.getUTCHours());     // 14
console.log(eventUtc.getUTCMinutes()); // 30
console.log(eventUtc.getUTCSeconds()); // 45
Try It Yourself

How It Works

Date.UTC accepts hour, minute, and second arguments. UTC getters read back the same second value everywhere, regardless of the user’s timezone.

Example 3 — Validate Before Calling getUTCSeconds()

Guard against invalid Date objects that yield NaN.

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

console.log(safeGetUTCSeconds(new Date(Date.UTC(2026, 6, 4, 14, 30, 45)))); // 45
console.log(safeGetUTCSeconds(new Date("not-a-date")));                      // null
Try It Yourself

How It Works

getTime() returns NaN on invalid dates. Checking first keeps UTC clock UI from showing broken values.

Example 4 — Build a UTC HH:MM:SS Clock String

Combine padded UTC hour, minute, and second getters.

JavaScript
function formatUtcTime(date) {
  const h = String(date.getUTCHours()).padStart(2, "0");
  const m = String(date.getUTCMinutes()).padStart(2, "0");
  const s = String(date.getUTCSeconds()).padStart(2, "0");
  return h + ":" + m + ":" + s + " UTC";
}

console.log(formatUtcTime(new Date(Date.UTC(2026, 6, 4, 9, 5, 7))));
// "09:05:07 UTC"
Try It Yourself

How It Works

Pad all three parts for a fixed-width UTC clock. For production, Intl.DateTimeFormat with timeZone: "UTC" handles locale rules automatically.

Example 5 — Compare getSeconds() and getUTCSeconds()

The same instant can show different second values in local time vs UTC near minute boundaries.

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

console.log("UTC seconds:", date.getUTCSeconds());   // 30
console.log("Local seconds:", date.getSeconds());    // depends on timezone
Try It Yourself

How It Works

At 20:45:30 UTC on June 15, it is 02:16:00 on June 16 in UTC+5:30. getUTCSeconds() stays 30; getSeconds() becomes 0. Use UTC getters when cron rules follow UTC.

🚀 Common Use Cases

  • UTC cron jobs — trigger at second 0 of each UTC minute.
  • Log timestamps — show UTC HH:MM:SS in debug panels.
  • API rate windows — bucket requests by UTC second for short intervals.
  • Manual formatting — build UTC clocks with getters.
  • Test fixtures — assert second parts from Date.UTC.
  • Countdown displays — derive remaining time from getTime(), not getter subtraction.

🧠 How getUTCSeconds() Resolves the Second

1

Internal instant

The Date stores milliseconds since Unix epoch (UTC).

Storage
2

UTC projection

Engine reads UTC time fields, including the current minute.

UTC
3

Extract second

Second within that UTC minute (0–59) is returned.

getUTCSeconds
4

Format or schedule

Pad for clocks or pair with UTC minute checks.

📝 Notes

  • getUTCSeconds() is UTC; use getSeconds() for local UI clocks.
  • Returns 0–59 only—not total seconds since midnight.
  • For elapsed duration, use (end.getTime() - start.getTime()) / 1000.
  • Invalid dates propagate NaN—validate with Number.isNaN(date.getTime()).
  • Pad with padStart(2, "0") for two-digit second displays.
  • For full UTC strings, toISOString() is often simpler than manual getters.

Browser & Runtime Support

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

Baseline · ES1

Date.prototype.getUTCSeconds()

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

Bottom line: Safe everywhere. Pair UTC getters together and use getTime() for elapsed second calculations.

Conclusion

getUTCSeconds() reads the second component (0–59) from a JavaScript Date in UTC. Use it for UTC clocks and scheduling; use local getters or locale formatters when showing time to end users.

Next, learn Date.now() for the current timestamp in milliseconds, or review getSeconds() for local second reads.

💡 Best Practices

✅ Do

  • Validate dates before calling getUTCSeconds()
  • Pad seconds for fixed-width UTC clocks
  • Use getTime() for elapsed duration
  • Prefer Date.UTC in tests for stable fixtures
  • Document whether rules follow UTC or local time

❌ Don’t

  • Subtract getUTCSeconds() values for duration
  • Assume getSeconds() equals getUTCSeconds()
  • Display unpadded seconds in strict HH:MM:SS formats
  • Mix local and UTC getters in one label
  • Ignore NaN from bad date parses

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.getUTCSeconds()

Your foundation for UTC second reads in JavaScript.

5
Core concepts
🔢 02

0–59

UTC second.

Range
🌐 03

UTC

Not local.

Timezone
04

Pad 2

09:05:07 UTC.

Format
05

Elapsed

Use getTime().

Pitfall

❓ Frequently Asked Questions

An integer from 0 to 59 representing the seconds within the current UTC minute—not total seconds since midnight or since 1970.
getUTCSeconds() uses UTC rules. getSeconds() uses local timezone rules. They can differ when your offset shifts the minute.
getUTCSeconds() returns 0–59 for the second hand of the UTC clock. getUTCMilliseconds() returns 0–999 for the fraction inside the current UTC second.
NaN. Validate with Number.isNaN(date.getTime()) before using the result in UI or conditionals.
No for valid dates—the range is 0–59. When seconds overflow via setUTCSeconds, JavaScript normalizes into the next UTC minute.
Subtract getTime() values and divide by 1000: (end.getTime() - start.getTime()) / 1000. Do not subtract getUTCSeconds() values alone.
Did you know?

At 2026-06-15T20:45:30.000Z, getUTCSeconds() is always 30, but getSeconds() can be 0 in UTC+5:30—the same instant, different second on the clock.

Continue to Date.now()

Learn how to read the current timestamp as milliseconds since the Unix epoch.

Date.now() 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