I want to display x seconds ago
based on a MySQL Timestamp.
I found the plugin called timeago
But I cannot find a way to make it display only seconds.
I'm OK with 61 seconds, or 300 seconds. Any way to convert the output to seconds with timeago, or with pure jQuery / JavaScript ?
Thanks for any help !
Edit:
Sample Case :
$time1 = "2014-02-02 23:54:04"; // plus PHP ways to format it.
//$time2 = NOW() , or date(); whatever.
I just want to get how many seconds since $time1
.
Edit 2:
Working code :
<script type="text/javascript">
$(function(){
var d2 = new Date();
var d1 = new Date("2014-02-02 23:54:04");
$("a#timedif").html("Diff. Seconds : "+((d2-d1)/100).toString());
// note that you may want to round the value
});
</script>
It outputs Diff. Seconds : NaN
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…