Add 10 seconds to a Date

// let timeObject = new Date();
// let milliseconds= 10 * 1000; // 10 seconds = 10000 milliseconds
timeObject = new Date(timeObject.getTime() + milliseconds);

There's a setSeconds method as well:

var t = new Date();
t.setSeconds(t.getSeconds() + 10);

For a list of the other Date functions, you should check out MDN


setSeconds will correctly handle wrap-around cases:

var d;
d = new Date('2014-01-01 10:11:55');
alert(d.getMinutes() + ':' + d.getSeconds()); //11:55
d.setSeconds(d.getSeconds() + 10);
alert(d.getMinutes() + ':0' + d.getSeconds()); //12:05

Tags:

Javascript