How can I add 10 seconds to a JavaScript date object?
Something like this:
var timeObject = new Date() var seconds = timeObject.getSeconds() + 10; timeObject = timeObject + seconds;
There's a setSeconds method as well:
setSeconds
var t = new Date(); t.setSeconds(t.getSeconds() + 10);
For a list of the other Date functions, you should check out MDN
Date
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
1.4m articles
1.4m replys
5 comments
57.0k users