How To Get Current Date And Time In Node.js

Websolutionstuff
1 min readNov 19, 2021

--

In this example we will see how to get current date and time in Node.js application. In Node.js date and time are handled with the Javascript Date object. It is loaded by default and requires no import of modules.

Also you can get current date, month, year, hour, minutes & seconds in Node.js. In Node.js you can get the current date-time formatted as YYYY-MM-DD hh:mm:ss, YYYY-MM-DD, DD-MM-YYYY etc.

And I will share example about how to get the current timestamp and how to get date-time from a given timestamp.

Example 1 :

The current date and time can be fetched by creating a new Date object.

var express = require('express');
var app = express();

var date_time = new Date();
console.log(date_time);

app.listen(3000);

Output :

2021–08–28T08:39:45.558Z

--

--

Websolutionstuff
Websolutionstuff

Written by Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/

No responses yet