JavaScript Date setUTCSeconds() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

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

Remember
date.setUTCSeconds(secondsValue)
date.setUTCSeconds(sec, ms)

secondsValue → 0–59 (UTC)
overflow     → rolls into the next UTC minute
returns      → epoch milliseconds (or NaN)

setUTCSeconds() → UTC wall clock
setSeconds()    → local wall clock

Syntax

Call date.setUTCSeconds. Start with this line.

JavaScript
date.setUTCSeconds(s[, ms])
CallWhat it does
date.setUTCSeconds(s[, ms])Primary signature.
date.setUTCSeconds(...)Call with the arguments your case needs.

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

Library declarations
JavaScript
date.setUTCSeconds(s[, ms])

Parameters

ParameterDescription
secondsValueRequired. UTC seconds (0–59; overflow allowed)
msValueOptional. UTC milliseconds (0–999)

Return Value

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

JavaScript Examples

Example 1 — Set the UTC Second Only

Move the UTC second to 10 while keeping milliseconds.

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

console.log(date.getUTCSeconds());      // 10
console.log(date.getUTCMilliseconds()); // 250
console.log(date.toISOString());        // "2026-03-01T12:30:10.250Z"
Try It Yourself

How It Works

  1. Build a UTC date. Date.UTC(..., 45, 250) is 12:30:45.250 UTC.
  2. Change only the second. setUTCSeconds(10) writes second 10 and leaves ms alone.
  3. Read it back. getUTCSeconds() → 10, getUTCMilliseconds() → 250.
  4. Confirm ISO. The trailing Z means UTC — 12:30:10.250Z.

Example 2 — Snap to :15.000 UTC

Use two arguments to set seconds and milliseconds together.

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

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

How It Works

  1. Start messy. The date begins at 12:30:45.250 UTC.
  2. Pass two args. Second 15, then 0 for milliseconds.
  3. Clear leftovers. The .250 fraction becomes .000.
  4. Keep the minute. The UTC minute stays 30; only seconds and below change.

Example 3 — UTC Second Overflow (setUTCSeconds(75))

Out-of-range seconds roll into the next UTC minute.

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

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

How It Works

  1. Start at :45. The date is 12:30:45 UTC.
  2. Pass 75. 75 seconds = 1 full minute + 15 seconds.
  3. Normalize. Minute becomes 31, second becomes 15.
  4. Use carefully. Overflow helps when adding seconds, but it will not reject bad input.

Browser & Runtime Support

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

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

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

Frequently Asked Questions

It sets the seconds (0–59) of a Date according to universal time (UTC). An optional milliseconds argument can also set sub-second precision. The Date mutates in place and returns the new timestamp in milliseconds.
setSeconds() changes the local clock second. setUTCSeconds() changes the UTC clock second. Use the setter that matches your timezone rules—do not mix them with the opposite getters.
If you pass only the seconds, the current UTC milliseconds are kept (from getUTCMilliseconds).
JavaScript normalizes overflow into the next UTC minute. setUTCSeconds(75) becomes +1 minute and 15 seconds (milliseconds 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 and UTC schedules when you need to set or clear the second (and optional ms). Prefer setSeconds() for user-facing local clocks.

Next: toDateString()

Learn how to format a Date as a human-readable date string.

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.

11 people found this page helpful