Javascript Date getSeconds()

Introduction

Javascript Date getSeconds() returns the date's seconds as a number between 0 and 59.

Return value

An integer number, between 0 and 59.

var d = new Date('December 25, 1995 23:15:30');
var seconds = d.getSeconds();

console.log(seconds); // 30

Using getHours(), getMinutes(), and getSeconds() to display the time:

function addZero(i) {
  if (i < 10) {
    i = "0" + i;//from w ww .  j av  a 2  s .c  o  m
  }
  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);



PreviousNext

Related