The getSeconds() method returns the seconds ranged from 0 to 59 from the date object.
The getSeconds() method returns the seconds ranged from 0 to 59 from the date object.
Date.getSeconds()
None
A Number, from 0 to 59, representing the seconds
Return the seconds, according to local time:
//display the seconds of the time right now. var d = new Date(); var n = d.getSeconds(); console.log(n);// w w w . jav a2 s.co m
Using getHours(), getMinutes(), and getSeconds() to display the time:
//display the time. function addZero(i) { if (i < 10) { i = "0" + i; }/*from w ww . ja v a2s. c om*/ return i; } var d = new Date(); var h = addZero(d.getHours()); var m = addZero(d.getMinutes()); var s = addZero(d.getSeconds()); console.log( h + ":" + m + ":" + s);