How to get current timestamp in JavaScript

Getting the current timestamp is essential for logging, performance measurement, and unique ID generation in JavaScript applications. As the creator of CoreUI with over 25 years of development experience, I’ve used timestamps extensively in production systems for tracking user interactions and measuring component performance. The most efficient and widely supported method is using the Date.now() static method. This approach provides milliseconds since Unix epoch with minimal overhead and maximum browser compatibility.

Use Date.now() to get the current timestamp as milliseconds since Unix epoch.

const timestamp = Date.now() 

The Date.now() method returns the current timestamp as a number representing milliseconds elapsed since January 1, 1970 UTC. This static method doesn’t create a Date object, making it the fastest way to get the current time. The returned value can be used for calculations, logging, or converted back to a Date object when needed.

Best Practice Note:

This is the same approach we use in CoreUI components for performance monitoring and cache invalidation. Avoid new Date().getTime() when you only need the timestamp, as Date.now() is significantly faster and doesn’t create unnecessary objects.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to Add a Tab in HTML
How to Add a Tab in HTML

How to Open Link in a New Tab in HTML?
How to Open Link in a New Tab in HTML?

How to Disable Right Click on a Website Using JavaScript
How to Disable Right Click on a Website Using JavaScript

How to sleep in Javascript
How to sleep in Javascript

Answers by CoreUI Core Team