JavaScript Date getUTCSeconds() method

The getUTCSeconds method in JavaScript retrieves the seconds component of a given date, calculated according to Coordinated Universal Time (UTC).

Syntax

The syntax for the getUTCSeconds method can be expressed as follows:

Example

dateObj.getUTCSeconds()

Return

A whole number within the range of 0 to 59 that signifies the second.

JavaScript Date getUTCSeconds method example

In this section, we will explore the getUTCSeconds method by examining several examples.

Example 1

Let’s examine an example that demonstrates how to display the current second in accordance with Coordinated Universal Time (UTC).

Example

<script>

var sec=new Date();

document.writeln("Seconds Value : "+sec.getUTCSeconds());

</script>

Output:

Output

Seconds Value : 51

Example 2

Let’s examine an example that demonstrates how to output the value of seconds from a specified date based on universal time.

Example

<script>

var sec1=new Date("August 15 1975 22:59:30 GMT+7:00");

var sec2=new Date("August 15 1975 22:59:50 GMT+5:30");

document.writeln("Second value1 : "+sec1.getUTCSeconds()+"<br>");

document.writeln("Second value2 : "+sec2.getUTCSeconds());

</script>

Output:

Output

Second value1 : 30

Second value2 : 50

Input Required

This code uses input(). Please provide values below: