JavaScript Date getUTCSeconds() method

Definition and usage

getUTCSeconds() The method returns the number of seconds (from 0 to 59) for the specified date and time based on UTC.

When calculating dates, the UTC method assumes the date object is local time and date.

Tip:Coordinated Universal Time (UTC) is the standard time set for world time.

Note:UTC time is the same as GMT time (Greenwich Mean Time).

Example

Example 1

Return the number of seconds based on UTC:

var d = new Date();
var n = d.getUTCSeconds();

Try it yourself

Example 3

Display Coordinated Universal Time (UTC) using getUTCHours(), getUTCMinutes(), and getUTCSeconds():

function addZero(i) {
  if (i < 10) {
    i = "0" + i;
  }
  return i;
}
function myFunction() {
  var d = new Date();
  var x = document.getElementById("demo");
  var h = addZero(d.getUTCHours());
  var m = addZero(d.getUTCMinutes());
  var s = addZero(d.getUTCSeconds());
  x.innerHTML = h + ":" + m + ":" + s;
}

Try it yourself

Syntax

Date.getUTCSeconds()

Parameters

No parameters.

Technical details

Return value: numbers, from 0 to 59, represent seconds.
JavaScript version: ECMAScript 1

browser support

method Chrome IE Firefox Safari Opera
getUTCSeconds() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Object Constructor