jQuery event.timeStamp property with Example


The event.timeStamp property in jQuery is used to return the number of milliseconds since January 1, 1970, when the event is triggered.

Syntax

The syntax is as follows −

event.timeStamp

Example

Let us now see an example to implement the jQuery event.timeStamp property −

<!DOCTYPE html>
<html>
<head>
<style>
   .demo {
      color: white;
      background-color: black;
   }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("button").click(function(event){
         $("span").text(event.timeStamp);
      });
   });
</script>
</head>
<body>
<h2>Milliseconds January 1, 1970</h2>
<p>Event occurred <span class="demo">0</span> milliseconds after January 1, 1970.</p>
<button>Milliseconds</button>
</body>
</html>

Output

This will produce the following output −

Click on the button “Milliseconds” above −

Updated on: 12-Nov-2019

233 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements