ehsan ehsan - 5 months ago 8
jQuery Question

How can I get timeStamp in my code

I want when page loaded get timeStamp but I can't.

This is my code :

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id = "x">time</p>
<script src="jquery/jquery1.12.js"></script>
<script>
$(document).ready(function(event){
$("#x").text(event.timeStamp);
})
</script>
</body>
</html>

Answer

You can use Date object to do this work. now() method return timestamp in miliseconds. Of course javascript return timestamp with client time.

$(document).ready(function(event){
    var timeStamp = Math.floor(Date.now() / 1000);
    $("div").text(timeStamp);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>

Comments