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
date.setSeconds(seconds, [milliseconds]);
Example
Let's set the seconds for the current point in time:
let date = new Date();
date.setSeconds(59);
console.log(date);
Example
Let's set the seconds and milliseconds for the current point in time:
let date = new Date();
date.setSeconds(59, 999);
console.log(date);
See also
-
the
setHoursmethod
that sets the hours -
the
setMinutesmethod
that sets the minutes -
the
setSecondsmethod
that sets the seconds -
the
setMillisecondsmethod
that sets the milliseconds