![]() |
VOOZH | about |
The Date.now() method in JavaScript returns the current timestamp in milliseconds since January 1, 1970. This method doesn’t require creating a new date object, making it one of the fastest and most efficient ways to capture the current time in your code.
let curr_date = Date.now();Example 1: The below example of the Date now() method.
The time elapsed in millisecond is: 1720904397838
The code snippet utilizes `Date.now()` to retrieve the current timestamp in milliseconds since the Unix epoch. It stores this value in variable `A` and prints it, indicating the elapsed milliseconds since the epoch.
Example 2: This example of getting the current date using the Date.now() method.
The current date is: Sat Jul 13 2024 20:59:57 GMT+0000 (Coordinated Universal Time)
The code snippet generates a new Date object using the current timestamp from Date.now(). It then converts this date object to a string format using .toString() and logs it, displaying the current date and time.
We have a complete list of Javascript Date Objects, to check those please go through this article