JavaScript Date getSeconds() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

Date.prototype.getSeconds() returns the seconds for this date as an integer 0–59 in local time (MDN). It is read-only and does not change the Date.

Remember
date.getSeconds()

→ integer 0 … 59
→ NaN if the Date is invalid

Example (MDN-style):
  new Date(1969, 6, 20, 0, 20, 18).getSeconds() → 18

getSeconds()    → local seconds
getUTCSeconds() → UTC seconds

Syntax

Call date.getSeconds. Start with this line.

JavaScript
date.getSeconds()
CallWhat it does
date.getSeconds()Primary signature.
date.getSeconds(...)Call with the arguments your case needs.

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

Library declarations
JavaScript
date.getSeconds()

Parameters

This method has no parameters beyond those shown in the signature.

Return Value

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

JavaScript Examples

Example 1 — Read the Local Seconds

Call getSeconds() on fixed local date-times (MDN-style values).

JavaScript
const landing = new Date(1969, 6, 20, 0, 20, 18); // Jul 20, 1969 00:20:18
const night = new Date(1995, 11, 25, 23, 15, 30);

console.log(landing.getSeconds()); // 18
console.log(night.getSeconds());   // 30
Try It Yourself

How It Works

  1. Build local times. The sixth constructor argument is seconds.
  2. Landing. 00:20:18 → getSeconds() returns 18.
  3. Night. 23:15:30 → 30.
  4. No mutation. The Date values are unchanged.

Example 2 — getSeconds() vs getUTCSeconds()

Local and UTC seconds can disagree near minute boundaries.

JavaScript
const d = new Date("1995-12-25T23:15:30Z"); // 23:15:30 UTC

console.log(d.getUTCSeconds()); // 30
console.log(d.getSeconds());    // local seconds (often 30, sometimes not)
Try It Yourself

How It Works

  1. UTC instant. The Z suffix means 23:15:30 in UTC.
  2. UTC getter. getUTCSeconds() always reports 30 for that instant.
  3. Local getter. getSeconds() applies your timezone — usually 30, but can differ near minute edges.
  4. Rule. Need wall-clock local seconds → getSeconds(); need UTC → getUTCSeconds().

Example 3 — HH:MM:SS with Leading Zeros

Pad hours, minutes, and seconds for a simple digital clock string.

JavaScript
function clock(date) {
  const h = String(date.getHours()).padStart(2, "0");
  const m = String(date.getMinutes()).padStart(2, "0");
  const s = String(date.getSeconds()).padStart(2, "0");
  return h + ":" + m + ":" + s;
}

console.log(clock(new Date(2026, 0, 1, 9, 5, 5)));   // "09:05:05"
console.log(clock(new Date(2026, 0, 1, 14, 0, 0)));  // "14:00:00"
Try It Yourself

How It Works

  1. Read fields. Hours, minutes, and seconds come from the local getters.
  2. Pad. padStart(2, "0") turns 5 into "05".
  3. Join. Combine with ":" for HH:MM:SS.
  4. UI option. For locale-aware clocks, prefer toLocaleTimeString().

Browser & Runtime Support

Date.prototype.getSeconds() is part of the language from early ECMAScript and is Baseline Widely available (MDN).

✓ Baseline · Widely available

Date.prototype.getSeconds()

Supported in every modern browser and Node.js. No polyfill needed for ordinary web apps.

99% Modern browser support
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.getSeconds() Excellent

Bottom line: Safe everywhere. Focus on timezone choice (local vs UTC) and invalid-Date checks rather than feature detection.

Frequently Asked Questions

An integer from 0 to 59 representing the seconds within the current minute in local time. Invalid Dates return NaN.
getSeconds() uses local timezone rules. getUTCSeconds() reads the UTC second component. They can differ near minute boundaries across timezones.
getSeconds() returns 0–59 for whole seconds in the current minute. getMilliseconds() returns 0–999 for the fraction inside the current 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 setSeconds, JavaScript normalizes into the next minute.
No. getSeconds() only reads the clock second (0–59), not duration. Use Date.now(), getTime(), or performance.now() for timers.

Next: getMilliseconds()

Learn how to read the local milliseconds field (0–999) from a Date.

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