JavaScript getUTCSeconds

The JavaScript getUTCSeconds function returns the seconds value ranging from 0 to 59 from a given date according to Universal Coordinated Time (UTC).

The syntax of the getUTCSeconds function is:

 Date.getUTCSeconds()

Return Value: The getUTCSeconds method returns an integer value between 0 and 59 representing the seconds from a given date and time.

JavaScript getUTCSeconds example

In the following example, we use the getUTCSeconds method to return the total seconds as per Coordinated Universal Time (UTC) from the current date and time.

const dt = new Date();
let s = dt.getUTCSeconds();
console.log(s);
console.log(dt);
16 
Sat Jun 13 2026 13:11:16 GMT+0530 (India Standard Time)

Example 2: Use getUTCSeconds on a String

In this JavaScript example, we use the new Date() constructor to parse a string date. Next, we use the getUTCSeconds() method to display the seconds from the custom date and time as per universal time.

const dt = new Date("May 2, 2023 10:02:22");
console.log(dt.getUTCSeconds());
console.log(dt);
22 
Tue May 02 2023 10:02:22 GMT+0530 (India Standard Time)

Example 3: If we use the JavaScript getUTCSeconds() method on a date without time, it returns 0. By default, the Date() method adds 00:00:00 as the default time, so it returns 0.

const dt = new Date("May 2, 2023");
console.log(dt.getUTCSeconds());
console.log(dt);
0
Tue May 02 2023 00:00:00 GMT+0530 (India Standard Time)

Example 4: If we use the getUTCSeconds() function on an invalid date, it returns NaN as output.

const dt = new Date("2026-19-04");
console.log(dt.getUTCSeconds());
console.log(dt);
NaN 
Invalid Date

What is the difference between getSeconds() and getUTCSeconds ()?

Both getSeconds() and getUTCSeconds() methods return the seconds (0 to 59) values from the given date. As there is no second difference between UTC and local time zones, they return the same result.

const dt = new Date("2026-03-01 10:10:50");
console.log(dt.getUTCSeconds());
console.log(dt.getSeconds());
50
50