How To Date Add Year Using Node Js?

Dec 23, 2021 . Admin



Hello Friends,

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

Here i will give you many example how to date add year 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 addYear = new Date('2018/12/18');
addYear.setFullYear(addYear.getFullYear() + 1);

var getYear = addYear;

console.log(getYear);

now you can simply run by following command:

node server.js
Output :
2019-12-17T18:30:00.000Z

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 addYear = new Date();
addYear.setFullYear(addYear.getFullYear() + 1);

var getYear = addYear.toLocaleString();

console.log(getYear);

now you can simply run by following command:

node server.js
Output :
16/12/2022, 3:48:37 pm

It will help you...

#Node JS