Avatar ·

How to get a timestamp in JavaScript?

Hello everyone! I'm a beginner in JavaScript and writing a small script for a web application. I need to save the time when a user clicks a button, so I can later compare these moments or send them to the server. In other languages (for example, in PHP I saw `time()`) this is done with a single function. In JavaScript, I found the `Date` object, but it returns some strange string like "Fri Feb 02 2024 15:30:00 GMT+0300". I need just a number — the number of milliseconds or seconds, like it's usually stored in databases. I tried this: ```javascript let now = new Date(); console.log(now); // Outputs a string, not a number ``` Then I came across the `getTime()` method, but it returns a very large number like 1706873400000. Is that it? Or is there a simpler way? I also heard there is `Date.now()`.