JavaScript setUTCSeconds

The JavaScript setUTCSeconds function is useful for setting the Seconds and Milliseconds of a specified date according to the Universal Coordinated Time zone.

The syntax of the setUTCSeconds is:

 Date.setUTCSeconds(Seconds, Milliseconds)

Parameters: The setUTCSeconds method accepts seconds (required) and optional milliseconds parameters.  

Return Value: It updates or sets the UTC date to the given seconds and milliseconds. If the seconds value is greater than 59, it updates the minutes to the future.

JavaScript setUTCSeconds example

In the following example, we use setUTCSeconds to set the current UTC date seconds to 49 according to universal time.

const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCSeconds(49);
console.log(dt.toUTCString());
Mon, 15 Jun 2026 13:22:22 GMT 
Mon, 15 Jun 2026 13:22:49 GMT

Example 2: In this JavaScript set UTC Seconds example, we set the custom date UTC seconds to 55 according to universal time.

const dt = new Date("May 1, 2016 10:11:19");
console.log(dt.toUTCString());
dt.setUTCSeconds(55);
console.log(dt.toUTCString());
Sun, 01 May 2016 04:41:19 GMT 
Sun, 01 May 2016 04:41:55 GMT

Example 3: The JavaScript setUTCSeconds() method has an optional Milliseconds argument. We can use it to set the UTC seconds and milliseconds. In the following example, we set the UTC second to 55 and milliseconds to 333.

const dt = new Date();
console.log(dt.toISOString());
dt.setUTCSeconds(55, 333);
console.log(dt.toISOString());
2026-06-15T13:25:45.050Z 
2026-06-15T13:25:55.333Z

Does setUTCSeconds change the minutes or hour?

If you use the seconds value between 0 and 59, the answer is no. However, if you pass a value greater than 59, it changes the minutes or hours to the future. If the value is negative, it moves backwards.

In the following example, we used the setUTCSeconds with 320 seconds (300 = 5 minutes and an extra 20 seconds). So, it adds 5 minutes and 20 seconds to the current date and time.

const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCSeconds(320);
console.log(dt.toUTCString());
Mon, 15 Jun 2026 13:26:49 GMT 
Mon, 15 Jun 2026 13:31:20 GMT

Similarly, the following example rolls minutes backwards. When the setUTCSeconds() identifies a negative number, it moves to the previous minute, and -5 means subtract 5 seconds in the previous minute.

const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCSeconds(-5);
console.log(dt.toUTCString());
Mon, 15 Jun 2026 13:29:05 GMT 
Mon, 15 Jun 2026 13:28:55 GMT

Difference between SetSeconds vs setUTCSeconds in JavaScript?

The setSeconds method updates the seconds value of a given date according to the local system time zone. However, the setUTCSeconds() sets the UTC seconds value according to the Universal Coordinated Time zone.

const dt = new Date();
dt.setUTCSeconds(50);
console.log(dt.toUTCString());
const d= new Date();
d.setSeconds(50);
console.log(d.toString());
Mon, 15 Jun 2026 13:32:50 GMT 
Mon Jun 15 2026 19:02:50 GMT+0530 (India Standard Time)