How to Get Current Month in Node.js?
Hi Dev,
This tutorial will show you how to get the current month in node.js. you will learn how to get the current month in nodejs. if you have a question about how to get the current month in node js then I will give a simple example with a solution. This article will implement a node js to get a current month.
In this tutorial, we learn to get current month in node js. I will use this example Date() and getMonth() to get current month. Date() function used to get current date and getMonth() get current month. There are several ways to get the month 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
//create month array list
monthArray = ['January', 'February', 'March', 'April', 'May', 'June', 'July','August','September','October','November','December'];
//get month using getMonth()
month = new Date().getMonth();
//get month name
monthName = monthArray[month];
//print month name
console.log(monthName);
Output:
September
- 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?