How To Use Date Sub Hours Using Node Js?


Share:
 | Published By: Admin | Published On: Dec 27, 2021 | Category: Node JS


Hello Friends,

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

Here i will give you many example how to use date sub 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 subHr = new Date();
subHr.setHours( subHr.getHours() - 3 );

console.log( subHr.toLocaleString() );

now you can simply run by following command:

node server.js
Output :
20/12/2021, 1:48:12 pm

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 dt = new Date("2021-9-12 11:19:20");
dt.setHours( dt.getHours() - 1 );

console.log( dt.toLocaleString() );

now you can simply run by following command:

node server.js
Output :
12/9/2021, 10:19:20 am

It will help you...

Share: