How to Get Current Date and Time in Node.js?

Sep 05, 2022

.

Admin

How to Get Current Date and Time in Node.js?

Hi Dev,

In this example, I will show you how to get the current date and time in node js. I’m going to show you to get current date and time in node.js. I would like to show you get current date and time in node js. This article will give you a simple example of get the current date in nodejs.

In this tutorial, we learn to get current date and time in node js. I will use this example Date() to get current date and time. Date() function used to get current date and time. There are several ways to get the time and date 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 current fullDateTime

fullDateTime = `${date}`

// print date

console.log(fullDateTime);

Output:

Mon Sep 05 2022 11:23:11 GMT+0530 (India Standard Time)

I hope it can help you...

#Node JS