JavaScript .setSeconds()
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.
Syntax
myDate.setSeconds(secondsValue)
The returned value from .setSeconds() modifies the original Date object, myDate, by setting the seconds to secondsValue.
Example
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');myDate.setSeconds(42);console.log(myDate.toString());
This results in the following output:
Mon Aug 29 2022 23:15:42 GMT+0000
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours