Node JS Get Current Date And Time Example

In this article, we will see node js get the current date and time example. Here, we will learn about how to get the current date and time in the 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 the 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.

So, let's see get the current time in node js, node js get a current timestamp, how to get current date and time in node js, node js date format, node js get a current timestamp, node.js get current date yyyy-mm-dd with time.

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();

Output : 




Example 2:

In this example we will see different methods and get output in YYYY-MM-DD hh:mm:ss format.

const express = require("express")
const app = express()

let date_time = new Date();

// get current date
// adjust 0 before single digit date
let date = ("0" + date_time.getDate()).slice(-2);

// get current month
let month = ("0" + (date_time.getMonth() + 1)).slice(-2);

// get current year
let year = date_time.getFullYear();

// get current hours
let hours = date_time.getHours();

// get current minutes
let minutes = date_time.getMinutes();

// get current seconds
let seconds = date_time.getSeconds();

// prints date in YYYY-MM-DD format
console.log(year + "-" + month + "-" + date);

// prints date & time in YYYY-MM-DD HH:MM:SS format
console.log(year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds);



2023-04-22 10:27:21



Example 3:

Get the current timestamp using method. Note that this method returns the timestamp in milliseconds. To get the timestamp as seconds we can divide it by 1000. returns the number of milliseconds since January 1, 1970.

Note: is a static method of the Date object.

You cannot use it on a date like

The syntax is always

let timestamp =;

// timestamp in milliseconds

// timestamp in seconds





Example 4:

In this example, we will get the Date and Time from Timestamp. And timestamps are specified as milliseconds. if the given timestamp is in seconds you will need to convert the same to milliseconds by multiplying with 1000.

// current timestamp in milliseconds
let ts =;

let date_time = new Date(ts);
let date = date_time.getDate();
let month = date_time.getMonth() + 1;
let year = date_time.getFullYear();

// prints date & time in YYYY-MM-DD format
console.log(year + "-" + month + "-" + date);




You might also like:


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.