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 »
getSeconds()
returns the seconds (0 to 59) of a date.
Date.getSeconds()
NONE |
Type | Description |
A number | The seconds of the date (0 to 59). |
getSeconds()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!