JavaScript Date setUTCSeconds() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
UTC second 0–59

What You’ll Learn

setUTCSeconds() writes the second (0–59) on a Date in UTC, with optional milliseconds. This guide covers syntax, minute snaps, combined second/ms overload, overflow, and comparisons with local setSeconds().

01

Syntax

setUTCSeconds(s)

02

0–59 UTC

Second hand

03

+ ms

2-arg form

04

:00 snap

Minute start

05

Overflow

Rolls minutes

06

Returns

Epoch ms

Introduction

ISO timestamps and server logs often need precise UTC second fields. After reading the UTC second with getUTCSeconds(), setUTCSeconds() writes it back without local timezone offsets.

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

Understanding the setUTCSeconds() Method

Date.prototype.setUTCSeconds(second [, millisecond]) accepts a UTC second and an optional UTC millisecond. When you pass only the second, UTC milliseconds stay the same unless overflow normalization rolls the clock.

Verify results with toISOString() or UTC getters. For a full UTC time including ms in one call, use setUTCHours(h, m, s, ms) or setUTCMinutes(m, s, ms).

💡
Beginner Tip

To snap to the start of a UTC minute: date.setUTCSeconds(0, 0). To pin :45.500 UTC: date.setUTCSeconds(45, 500).

📝 Syntax

JavaScript
dateObj.setUTCSeconds(second)
dateObj.setUTCSeconds(second, millisecond)

Parameters

  • second — Integer 0–59 in UTC time (overflow normalizes).
  • 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 second onlydate.setUTCSeconds(30)
Snap to start of UTC minutedate.setUTCSeconds(0, 0)
Set s and ms togetherdate.setUTCSeconds(45, 500)
Read UTC second after setdate.getUTCSeconds()
Local second setterdate.setSeconds(30)
Verify ISO outputdate.toISOString()

📋 setUTCSeconds() vs Similar Methods

Pick the setter that matches the time field and timezone you need.

setUTCSeconds()
UTC 0–59

UTC second

getUTCSeconds()
read

Getter pair

setSeconds()
local 0–59

Local setter

setUTCMilliseconds()
UTC ms

Sub-second only

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 second while keeping minutes and hours.

Example 1 — Set the UTC Second to 30 (Keep Minutes and Hours)

Start at 12:15:05 UTC and move the second hand to 30.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 12, 15, 5));
date.setUTCSeconds(30);

console.log(date.getUTCMinutes());  // 15
console.log(date.getUTCSeconds());  // 30
console.log(date.toISOString());    // "2026-03-01T12:15:30.000Z"
Try It Yourself

How It Works

Passing one argument updates only the UTC second. Minutes and hours remain unless normalization rolls the clock.

📈 Practical Patterns

UTC minute snaps, combined second/ms, cloning, and overflow.

Example 2 — Snap to Start of UTC Minute (setUTCSeconds(0, 0))

Clear UTC seconds and milliseconds while keeping hour and minute.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 12, 15, 42, 750));
date.setUTCSeconds(0, 0);

console.log(date.getUTCMinutes());         // 15
console.log(date.getUTCSeconds());         // 0
console.log(date.getUTCMilliseconds());    // 0
console.log(date.toISOString());           // "2026-03-01T12:15:00.000Z"
Try It Yourself

How It Works

Useful for minute-granularity UTC comparisons or grouping log entries by UTC minute.

Example 3 — Set UTC Seconds and Milliseconds Together

Pin an exact sub-minute UTC timestamp with one call.

JavaScript
const date = new Date(Date.UTC(2026, 2, 1, 9, 0, 0, 0));
date.setUTCSeconds(45, 500);

console.log(date.getUTCSeconds());         // 45
console.log(date.getUTCMilliseconds());    // 500
console.log(date.toISOString());           // "2026-03-01T09:00:45.500Z"
Try It Yourself

How It Works

The two-argument form sets both the UTC second and millisecond fields at once.

Example 4 — Clone, Then Set (Immutable Style)

Preserve the original Date by copying before mutating UTC seconds.

JavaScript
const original = new Date(Date.UTC(2026, 2, 1, 12, 15, 10));
const adjusted = new Date(original);
adjusted.setUTCSeconds(55);

console.log("Original s:", original.getUTCSeconds());  // 10
console.log("Adjusted s:", adjusted.getUTCSeconds());  // 55
Try It Yourself

How It Works

Setters always mutate their target. Clone first when other code still needs the old instant.

Example 5 — UTC Second Overflow (setUTCSeconds(90))

Passing 90 rolls into the next UTC minute at second 30.

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

console.log(date.getUTCMinutes());  // 31
console.log(date.getUTCSeconds());  // 30
Try It Yourself

How It Works

90 seconds = 1 minute + 30 seconds. The engine normalizes instead of clamping to 59.

🚀 Common Use Cases

  • UTC log alignmentsetUTCSeconds(0, 0) for minute buckets.
  • ISO timestamps — apply second/ms from parsed UTC strings.
  • Test fixtures — pin exact UTC second/ms with Date.UTC().
  • Cron alignment — snap events to :00 at UTC minute boundaries.
  • API sync — align server timestamps to UTC second precision.
  • Clone + mutate — keep originals when tweaking sub-minute UTC fields.

🧠 How setUTCSeconds() Updates the UTC Clock

1

Read UTC time

Engine loads UTC hour, minute, second, and ms fields.

UTC
2

Apply new second

Second and optional ms replace old UTC values.

setUTCSeconds
3

Normalize overflow

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

Normalize
4

Mutate & return ms

Date updates in place; epoch milliseconds are returned.

📝 Notes

  • setUTCSeconds() adjusts the second hand in UTC (0–59 typical range).
  • 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 (second 90 → next UTC minute + 30 seconds).
  • Omitting the ms argument does not reset milliseconds to zero.
  • Use setSeconds for local clocks; setUTCSeconds for ISO/server rules.

Browser & Runtime Support

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

Baseline · ES1

Date.prototype.setUTCSeconds()

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

Bottom line: Safe everywhere. Remember UTC vs local setters, mutation, and the two-argument snap pattern.

Conclusion

setUTCSeconds() writes the UTC second (and optionally milliseconds) on a JavaScript Date. Use it for ISO-aligned sub-minute precision; use setSeconds() for local wall clocks.

That completes the UTC setter family. Next, learn toDateString() for readable local date labels, or review getUTCSeconds() for reading the UTC second.

💡 Best Practices

✅ Do

  • Use setUTCSeconds(0, 0) to snap to UTC minute boundaries
  • Verify with toISOString() after changes
  • Pair with getUTCSeconds() for read/write workflows
  • Use the two-arg overload for exact :SS.ms UTC marks
  • Clone before mutating shared Date instances

❌ Don’t

  • Mix setUTCSeconds with getSeconds() in one calculation
  • Chain setters on the numeric return value
  • Assume values clamp at 59 (overflow rolls minutes)
  • Use setUTCSeconds(n) as a countdown timer (use epoch math instead)
  • Use local setters when ISO UTC rules apply

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.setUTCSeconds()

Your foundation for UTC second writes in JavaScript.

5
Core concepts
🌐 02

0–59 UTC

Second hand.

Range
📈 03

2 args

s + ms.

Overload
📈 04

:00 snap

Minute start.

Pattern
🔄 05

Mutates

In place.

Behavior

❓ Frequently Asked Questions

It sets the seconds (0–59) of a Date object in UTC. An optional milliseconds argument can also set sub-second precision. The Date mutates in place and returns updated epoch milliseconds.
getUTCSeconds() reads the current UTC second. setUTCSeconds(s) writes a new UTC second. They are the read/write pair for the second hand of the UTC clock.
Yes. setUTCSeconds(second, millisecond) updates both UTC fields at once—useful for snapping to :00.000 at the start of a UTC minute.
JavaScript normalizes overflow into the next UTC minute. setUTCSeconds(90) on 12:30:45 UTC becomes 12:31:30 UTC (90 seconds = 1 minute + 30 seconds).
No. It returns a number (epoch milliseconds). Call each setter on the same Date variable—do not chain on the return value.
setUTCSeconds() changes the UTC clock second. setSeconds() changes the local clock second. Use the one that matches your timezone rules.
Did you know?

setUTCSeconds(0, 0) snaps ISO strings to ...:MM:00.000Z—the same instant may show non-zero local seconds in getSeconds() when your timezone offset is not a whole number of hours.

Continue to toDateString()

Format a Date as a readable local calendar date string without the time.

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