How to Get a Timestamp in JavaScript?

Spread the love

Sometimes, we want to get a timestamp in JavaScript.

In this article, we’ll look at how to get a timestamp in JavaScript.

How to Get a Timestamp in JavaScript?

To get a timestamp in JavaScript, we can use some operators and functions.

For instance, we write

+new Date();
new Date().getTime();
Number(new Date())

to return the timestamp of the current datetime.

We use + before new Date() to get the timestamp of the current datetime in milliseconds.

Likewise, we use the getTime method to return the same thing.

Also, we can call Number with new Date() to return the current datetime’s timestamp

Conclusion

To get a timestamp in JavaScript, we can use some operators and functions.

Leave a Reply

Your email address will not be published.