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
Answer from zzzzBov on Stack Overflow Top answer 1 of 14
631
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
2 of 14
197
let timeObject = new Date();
const milliseconds = 10 * 1000; // 10 seconds = 10000 milliseconds
timeObject = new Date(timeObject.getTime() + milliseconds);
W3Schools
w3schools.com › jsref › jsref_setseconds.asp
JavaScript Date setSeconds() Method
cssText getPropertyPriority() getPropertyValue() item() length parentRule removeProperty() setProperty() JS Conversion · ❮ Previous JavaScript Date Reference Next ❯ · Set the seconds to 35: const d = new Date("2025-01-15"); d.setSeconds(35); Try it Yourself » ·
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › setSeconds
Date.prototype.setSeconds() - JavaScript | MDN
The setSeconds() method of Date instances changes the seconds and/or milliseconds for this date according to local time. const event = new Date("August 19, 1975 23:15:30"); event.setSeconds(42); console.log(event.getSeconds()); // Expected output: 42 console.log(event); // Expected output: ...
Futurestud.io
futurestud.io › tutorials › add-seconds-to-a-date-in-node-js-and-javascript
Add Seconds to a Date in Node.js and JavaScript
First, create a new date representing “now”. Then, replace the seconds of the “now” date by adding the delay to the current time:
TutorialsPoint
tutorialspoint.com › How-to-add-10-seconds-to-a-JavaScript-date-object
How to add 10 seconds to a JavaScript date object?
<html> <head> <title>Example- adding 10 seconds to a JavaScript date object</title> </head> <body> <h3> Add 10 seconds to the JavaScript Date object using setSeconds( ) method </h3> <p> Click on the button to add 10 seconds to the current date/time.</p> <button onclick="add()">Click Me</button> ...
Envato Tuts+
webdesign.tutsplus.com › home › web design › html/css › javascript for designers
How to Add and Subtract Time From a Date in JavaScript | Envato Tuts+
September 19, 2023 - Basically, we’ve just multiplied the number of minutes in an hour (60) by the number of seconds in a minute (60) by the number of milliseconds in a second (1000) to get the number of milliseconds in an hour. As you might already know, you can initialize a Date object by providing the number of milliseconds as the first argument, and this would initialize a date object in reference to it. Thus, we’ve added numberOfMlSeconds and addMlSeconds to get the total number of milliseconds, and we’ve used it to initialize a new date object.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › setHours
Date.prototype.setHours() - JavaScript | MDN
The setHours() method of Date instances changes the hours, minutes, seconds, and/or milliseconds for this date according to local time. const event = new Date("August 19, 1975 23:15:30"); event.setHours(20); console.log(event); // Expected output: "Tue Aug 19 1975 20:15:30 GMT+0200 (CEST)" ...
W3Schools
w3schools.com › jsref › jsref_getseconds.asp
JavaScript Date getSeconds() Method
cssText getPropertyPriority() ...tSeconds()); let time = h + ":" + m + ":" + s; Try it Yourself » · getSeconds() returns the seconds (0 to 59) of a date....
GeeksforGeeks
geeksforgeeks.org › node.js › node-js-date-and-time-date-addseconds-method
Node.js date-and-time Date.addSeconds() Method - GeeksforGeeks
March 25, 2021 - // Node.js program to demonstrate the // Date.addSeconds() method // Importing date-and-time module const date = require('date-and-time') // Creating object of current date and time // by using Date() const now = new Date(); now.setDate(20) ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getSeconds
Date.prototype.getSeconds() - JavaScript | MDN
The seconds variable has value 30, based on the value of the Date object xmas95. js · const xmas95 = new Date("1995-12-25T23:15:30"); const seconds = xmas95.getSeconds(); console.log(seconds); // 30 · Date.prototype.getUTCSeconds() Date.prototype.setSeconds() Was this page helpful to you?
Codecademy
codecademy.com › docs › javascript › dates › .setseconds()
JavaScript | Dates | .setSeconds() | Codecademy
June 21, 2023 - In the example below, the myDate variable is declared and then the .setSeconds() method is applied to return a modified time. const myDate = new Date('August 29, 2022 23:15:30'); ... Learn how to use JavaScript — a powerful and flexible ...
Day.js
day.js.org › docs › en › manipulate › add
Add · Day.js
result = dayjs().add(dayjs.duration({'days' : 1}))