event.timeStamp Property - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:event.timeStamp

Description

The event.timeStamp property returns the time stamp of an event as number of milliseconds since January 1, 1970.

Syntax

Parameter RequireDescription
event Required. The event parameter comes from the event binding function

The following code shows how to Return the number of milliseconds since Jan 1, 1970, when the click event occurs for a button:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    var lastms, d;//from w  ww.j a v a  2  s.co  m
    $("button").click(function(event){
        if (lastms){
            d = event.timeStamp - lastms
            $("p").text("Milliseconds since last click event: " + d);
        } else {
            $("p").text("Click the button again.");
        }
    lastms = event.timeStamp;
    });
});
</script>
</head>
<body>

<button>Click me</button>

<p></p>

</body>
</html>

Related Tutorials