Reputation: 12959
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>
Upvotes: 0
Views: 1023
Reputation: 5908
You will not get event object in ready call. As a workaround you can use $.now()
for instance:
$(document).ready(function(){
$("#x").text($.now());
});
Upvotes: 1
Reputation: 21489
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>
Upvotes: 1