Javascript Date getUTCSeconds()

Introduction

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

Return value

An integer number, between 0 and 59, representing the seconds in the given date according to universal time.

var today = new Date();
var seconds = today.getUTCSeconds();
console.log(seconds);//from  w w  w  .  j  av  a2  s .  c  om

Using getUTCHours(), getUTCMinutes(), and getUTCSeconds() to display the universal time:

function addZero(i) {
  if (i < 10) {
    i = "0" + i;/*w  w w  .  j  ava  2s  .  com*/
  }
  return i;
}

var d = new Date();
var h = addZero(d.getUTCHours());
var m = addZero(d.getUTCMinutes());
var s = addZero(d.getUTCSeconds());
console.log(h + ":" + m + ":" + s);



PreviousNext

Related