Javascript - Date getUTCSeconds() Method

The getUTCSeconds() method returns the seconds ranged from 0 to 59 of the date object, according to universal time.

Description

The getUTCSeconds() method returns the seconds ranged from 0 to 59 of the date object, according to universal time.

UTC time is the same as GMT time.

Syntax

Date.getUTCSeconds()

Parameters

None

Return

A Number, from 0-59, representing the seconds

Example

Return the seconds, according to universal time:

Demo

//display seconds, according to UTC.

var d = new Date();
var n = d.getUTCSeconds();
console.log(n);/*ww  w.j a  va 2 s  .  c om*/

Result

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

Demo

//display the UTC time.
function addZero(i) {
    if (i < 10) {
        i = "0" + i;
    }/*  www  .j  a  va  2s . c  o m*/
    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);

Result