Javascript Date setSeconds(seconds)

Introduction

Javascript Date setSeconds(seconds) sets the date's seconds.

dateObj.setSeconds(secondsValue[, msValue])

Parameters

  • secondsValue - An integer between 0 and 59, representing the seconds.
  • msValue - Optional. A number between 0 and 999, representing the milliseconds.

Return value

The number of milliseconds between 1 January 1970 00:00:00 UTC and the updated date.

If a parameter is outside of the expected range, setSeconds() updates the date accordingly.

Setting the seconds to a number greater than 59 also increments the minutes.

Get the date for '70 seconds after now':

let date = new Date();
date.setSeconds(date.getSeconds() + 70);

console.log( date ); // shows the correct date



PreviousNext

Related