How to Add Seconds to a JavaScript Date Object?

To add any number of seconds to an already instantiated Date object, you can simply add them to the seconds from that Date object. This would give you the total number of seconds, which you can then set on the Date object using the Date.prototype.setSeconds() method.

For example, to add 60 seconds to a JavaScript Date object that's instantiated to 'July 16, 2021 00:00:30', you could do the following:

const dt = new Date('July 16, 2021 00:00:30');
const secsToAdd = 60;
const totalSecs = dt.getSeconds() + secsToAdd;

dt.setSeconds(totalSecs);

console.log(dt); // 'Fri Jul 16 2021 00:01:30 GMT+0200 (Central European Summer Time)'

Hope you found this post useful. It was published . Please show your love and support by sharing this post.