How to add seconds to a date in Node.js

1 Answer

0 votes
function addSecondstoDate(seconds, date = new Date()) {
  	date.setSeconds(date.getSeconds() + seconds);

  	return date;
}


const date = new Date('2022-03-08T10:19:31');

console.log(addSecondstoDate(40, date).toString());


  
  
  
  
/*
run:
  
Tue Mar 08 2022 10:20:11 GMT+0000 (Coordinated Universal Time)
  
*/

 



answered Mar 21, 2022 by avibootz

Related questions

1 answer 260 views
1 answer 267 views
1 answer 219 views
1 answer 216 views
216 views asked Mar 22, 2022 by avibootz
1 answer 226 views
226 views asked Mar 22, 2022 by avibootz
1 answer 231 views
231 views asked Mar 21, 2022 by avibootz
...