JavaScript getUTCSeconds(): Get the UTC Seconds

The JavaScript getUTCSeconds() method is used to get the seconds (0-59) of the UTC time. UTC stands for Universal Time Coordinated, which is the same as Greenwich Mean Time (GMT). Here is an example of how to use getUTCSeconds() to print the seconds of the UTC time:

HTML with JavaScript Code
<!DOCTYPE html>
   <p id="xyz"></p>

      const d = new Date();
      let min = d.getUTCSeconds();
      document.getElementById("xyz").innerHTML = min;


The preceding example shows how to use JavaScript's getUTCSeconds() function to retrieve the second value of the current UTC time.

In the above example, using the following statement,

const d = new Date();

A new "Date" object is created and assigned to the constant variable "d." The "Date" object represents the current date and time.

The function getUTCSeconds() is then called on the "d" object, and the result is saved in the "min" variable. This function returns the current UTC time in seconds.

The value of the "min" variable is then set as the "innerHTML" property of the "p" element with the ID "xyz." On the web page, this displays the second value.

Therefore, when the code is executed, the value of the "min" variable (current UTC seconds) is displayed on the web page.

JavaScript getUTCSeconds() syntax

The syntax of the getUTCSeconds() method in JavaScript is:


where x must be an object of the Date() constructor.

The getUTCSeconds() method returns a number from 0 to 59, which will be the seconds of a date.

Advantages of the getUTCSeconds() function in JavaScript

Disadvantages of the getUTCSeconds() function in JavaScript

JavaScript Online Test

« Previous Tutorial Next Tutorial »

Liked this post? Share it!