JavaScript Date getSeconds()
Examples
Get the seconds:
const d = new Date();
let seconds = d.getSeconds();
Try it Yourself »
Add zeros and colons to display the time:
function addZero(i) {
if (i < 10) {i = "0" + i}
return i;
}
const d = new Date();
let h = addZero(d.getHours());
let m = addZero(d.getMinutes());
let s = addZero(d.getSeconds());
let time = h + ":" + m + ":" + s;
Try it Yourself »
Description
getSeconds()
returns the seconds (0 to 59) of a date.
Syntax
Date.getSeconds()
Parameters
NONE |
Return Value
Type | Description |
A number | The seconds of the date (0 to 59). |
Browser Support
getSeconds()
is an ECMAScript1 (JavaScriopt 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |