.setUTCSeconds()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jul 29, 2023
Contribute to Docs

The .setUTCSeconds() method sets the second value of a Date object according to Coordinated Universal Time(UTC) and returns the updated Date object.

Syntax

myDate.setUTCSeconds(secondsValue)
myDate.setUTCSeconds(secondsValue, millisecondsValue)

The .setUTCSeconds() method is called on the myDate object with an input argument secondsValue that passes the new value for seconds.

Optionally, the method can also set the date’s millisecond UTC values. The valid number ranges for the time units are as follows:

  • Seconds (Required): 0 to 59
  • Milliseconds (optional): 0 to 999

Example

This example sets the second value of the eventSeconds object to 35.

const eventSeconds = new Date('2023-06-25T00:00:00');
eventSeconds.setUTCSeconds(35);
console.log(eventSeconds);

This example will output the following:

2023-06-25T00:00:35.000Z

Codebyte Example

This code example sets the second and millisecond values of eventSeconds to 35 and 465 respectively. The values are then logged to the console.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn JavaScript on Codecademy