getSeconds() returns the seconds component of a JavaScript Date according to local time. The normal range is 0 to 59.
const now = new Date();
const value = now.getSeconds();
console.log(value);
const value = date.getSeconds();
The method takes no parameters. If the Date is invalid, it returns NaN.
const value = String(date.getSeconds()).padStart(2, "0");
const now = new Date();
const hh = String(now.getHours()).padStart(2, "0");
const mm = String(now.getMinutes()).padStart(2, "0");
const ss = String(now.getSeconds()).padStart(2, "0");
console.log(`${{hh}}:${{mm}}:${{ss}}`);
For an updating display, see the JavaScript clock and timer tutorial.
const localValue = date.getSeconds();
const utcValue = date.getUTCSeconds();
Use the local method for the host's local time and the UTC method when your logic is explicitly based on UTC. See UTC date methods.
const bad = new Date("invalid");
console.log(bad.getSeconds()); // NaN
getSeconds() returns whole seconds. Use getMilliseconds() for the 0–999 millisecond component or getTime() for the complete timestamp.
const seconds = date.getSeconds();
const milliseconds = date.getMilliseconds();
The original demo endpoint remains available at seconds demo.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.