How to Use Date Add Seconds using Node Js?

Dec 30, 2021 . Admin



Hello Friends,

Now let's see example of how to use date add seconds example. We will check how to use date add seconds. This is a short guide on use date add seconds in node js. Let's get started with how to use date add seconds in node js.

Here i will give you many example how to use date add seconds using node js.

Example 1 :

Step 1 : Create Node App

Run following command to create node app.

mkdir my-app
cd my-app
 
npm init
Step 2 : Create server.js file

server.js

var dtSecond;
dtSecond = new Date('2020-10-25 12:12:30');

console.log(dtSecond.getMinutes() + ':' + dtSecond.getSeconds());

dtSecond.setSeconds(dtSecond.getSeconds() + 15);

console.log(dtSecond.getMinutes() + ':' + dtSecond.getSeconds());

now you can simply run by following command:

node server.js
Output :
12:30
12:45

Example 2 :

Step 1 : Create Node App

Run following command to create node app.

mkdir my-app
cd my-app
 
npm init
Step 2 : Create server.js file

server.js

var dtSecond;
dtSecond = new Date('2020-10-25 12:12:30');

console.log(dtSecond.getSeconds());

dtSecond.setSeconds(dtSecond.getSeconds() + 15);

console.log(dtSecond.getSeconds());

now you can simply run by following command:

node server.js
Output :
30
45

It will help you...

#Node JS