How to Get Current Year in Node.js?
Hi Dev,
This article will provide an example of how to get the current year in node.js. you can understand the concept of get the current year in nodejs. you will learn to get the current year in node js. This article will implement a node js to get the current year. follow bellow step for node.js get a current year.
In this tutorial, we learn to get current year in node js. I will use this example Date() and getFullYear() to get current year. Date() function used to get current date and getFullYear() get current year. There are several ways to get the year in a granular manner from this class.
So, let's start following example with output:
Step 1: Create Node.js Project
This step is not required; however, if you have not created the node js app, then you may go ahead and execute the below command:
mkdir my-app
cd my-app
npm init
Step 2: Update index.js file
index.js
//get current date
date = new Date()
//get year using getFullYear()
year = date.getFullYear();
//print current year
console.log(year);
Output:
2022
- How to Install Node Js and NPM Ubuntu?
- How to used Google ReCaptcha V3 in Node Js Express?
- How to Send Email with Attachment in Node js?
- How to Insert Data from Form into MySQL Database using Node js Express?
- Install Node Js and NPM Ubuntu 18.04/20.04/22.04 Tutorial
- How to Delete Data by id into MongoDB in Node JS?
- Install Node.js 16/17/18 on CentOS 8 Tutorial
- How to Upload File in MongoDB using Node js Express?