How to Add Seconds to a Date in JavaScript

 

To add seconds to a date in JavaScript, use the getSeconds() method to get the seconds, then call the setSeconds() method on the date, passing the sum of getSeconds() and the number of seconds to add as arguments.

 

var date = new Date('2022-04-17T00:00:00.000Z');
seconds = 6;
var newDate = date.setSeconds(date.getSeconds() + seconds);
console.log(newDate);

Tags:

Share:

Related posts