Search code snippets, questions, articles...

Get current timestamp in javascript

In this code post, we are going to describe different methods that can be used to get the timestamp using Javascript. We use the Javascript Date() function for that.
const timestamp = new Date().getTime();

Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool



Live Demo

Use getTime() function to get the current timestamp

The getTime() function of the javascript Date() method returns the current timestamp. We can use this timestamp to verify when the specific task was performed. Below is an example.

# Code example 2

const result = new Date().getTime();


In the above code snippet, we are using the 'new Date().getTime()' to get the current timestamp from a date.

Use plus '+' operator to get the timestamp in javascript

We can also use the plus '+' operator of Javascript to get the timestamp. You just need to place the + operator before the Date() function and it will return the timetstamp.


+ new Date()

# Code example 3

const timestamp = + new Date();




Try it yourself

const timestamp = new Date().valueOf();

The above code example shows how to get the current timestamp using the valueOf() function. It is a method of Javascript Date() function that returns the current timestamp.
Was this helpful?