How To Use Date Add Hours Using Node Js?

Dec 25, 2021 . Admin



Hello Friends,

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

Here i will give you many example how to use date add hours 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 dt = new Date("2020-04-21 10:30:11");
dt.setHours( dt.getHours() + 1 );

console.log( dt.toLocaleString() );

now you can simply run by following command:

node server.js
Output :
21/4/2020, 11:30:11 am

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 addHr = new Date();
addHr.setHours( addHr.getHours() + 2 );

console.log( addHr.toLocaleString() );

now you can simply run by following command:

node server.js
Output :
20/12/2021, 6:31:14 pm

It will help you...

#Node JS