Timestamp in JavaScript

How do you get a timestamp in JavaScript? How to change the format of the Timestamp?

Last updated:7/20/2021 1:45:07 AM

1 Answers

Ethan Karla
Ethan Karla

A timestamp or time stamp is the current time when an event is performed (or recorded) by a computer or digital camera. The current date and time are registered in a file and logged when data is created, executed, modified, or deleted. The computer records the date and time when an action is performed on a document or folder.

All functions that work with dates and times in JavaScript use the Date() object and its methods. The Date object provides various methods to get the current timestamp of the machine in JavaScript. JavaScript parses and returns a machine timestamp result in microseconds from January 1, 1970 00:00:00 UTC.

Let's understand it with the help of an example :

<!DOCTYPE html>

<html>
<body>
    <p id='demo'></p>
    <script>
        var timestamp = new Date();
        document.getElementById('demo').innerHTML = timestamp;
    </script>
</body>
</html>
//Expected Output : Thu Jul 22 2021 03:22:30 GMT-0700 (Pacific Daylight Time) [Current Day & Time]

Hope this code will be helpful for you.

Happy Coding!

Answer