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 160 views
1 answer 190 views
1 answer 142 views
1 answer 123 views
123 views asked Mar 22, 2022 by avibootz
1 answer 131 views
131 views asked Mar 22, 2022 by avibootz
1 answer 132 views
132 views asked Mar 22, 2022 by avibootz
1 answer 140 views
140 views asked Mar 21, 2022 by avibootz
...