How do I get a timestamp in JavaScript?

14    Asked by jaden_5415 in Java , Asked on Jul 10, 2025

This question explores how to retrieve the current time in JavaScript as a timestamp (milliseconds since epoch), and explains common methods like Date.now() and new Date().getTime().

Answered by Rahul verma

If you need to get the current timestamp in JavaScript—basically the number of milliseconds since January 1, 1970 (Unix epoch)—you’re in luck! JavaScript makes this super easy.

 1. Using Date.now() (Recommended)

let timestamp = Date.now();
console.log(timestamp); // Example: 1718576394852

  • This returns the current timestamp in milliseconds.
  • It’s short, clean, and widely used.

 2. Using new Date().getTime()

let timestamp = new Date().getTime();
console.log(timestamp);

  • Does the same thing as Date.now(), just slightly more verbose.
  • Useful if you already have a Date object.


Your Answer