Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jun 21, 2023
Contribute to Docs

The .setSeconds() method sets the seconds component of a Date object to a specified value. It takes an integer value as its parameter, representing the new value for the seconds.



The returned value from .setSeconds() modifies the original Date object, myDate, by setting the seconds to secondsValue.


In the example below, the myDate variable is declared and then the .setSeconds() method is applied to return a modified time.

const myDate = new Date('August 29, 2022 23:15:30');

This results in the following output:

Mon Aug 29 2022 23:15:42 GMT+0000

All contributors

Looking to contribute?

Learn JavaScript on Codecademy