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 257 views
1 answer 265 views
1 answer 214 views
1 answer 211 views
211 views asked Mar 22, 2022 by avibootz
1 answer 221 views
221 views asked Mar 22, 2022 by avibootz
1 answer 229 views
229 views asked Mar 21, 2022 by avibootz
...