How to Get Current Timestamp in Node JS?
Sep 15, 2022
Hi Frends,
Here, I will show you how to get the current timestamp in node js. In this article, we will implement how to get the current timestamp in nodejs. this example will help you get the current timestamp in nodejs. This post will give you a simple example of get the current timestamp in node.js. Here, Creating a basic example of nodejs get the current timestamp.
I will give you a simple example of get the current timestamp in node js. In this example get current timestamp using Date.now() in node js.
So let's start following example:
Step 1: Install Node JS
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 server.js file
server.js
const timestamp = Date.now();
// timestamp in milliseconds
console.log(timestamp);
// timestamp in seconds
console.log(Math.floor(timestamp/1000));
Output:
1663217847557
1663217847
- 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?