setSeconds method

The setSeconds method allows you to change the number of seconds for the date object. It takes the number of seconds as the first parameter. It can also take milliseconds.

Syntax

javascriptdate.setSeconds(seconds, [milliseconds]);

Example

Let's set the seconds for the current point in time:

javascriptlet date = new Date();
date.setSeconds(59);

console.log(date);

Example

Let's set the seconds and milliseconds for the current point in time:

javascriptlet date = new Date();
date.setSeconds(59, 999);

console.log(date);

See also