Nowadays timeago is the most important functionality in social networking sites, it helps to updating timestamps automatically. Recent days I received few requests from 9lessons readers that asked me how to implement timeago plugin with dynamic loading live data using PHP. In this post I am just presenting a simple tip to implement timeago in a better way.
Download Script Live Demo
Why Live Query
LiveQuery utilizes the power of jQuery selectors by binding events or firing callbacks for matched elements auto-magically, even after the page has been loaded and the DOM updated.
Previous Post: http://www.9lessons.info/2010/01/php-time-stamp-function.html
Code
Contains javascipt code. $(this).timeago()- here this element is refers to timeago class selector of the anchor tag.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.livequery.js"></script>
<script type="text/javascript" src="js/jquery.timeago.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".timeago").livequery(function() // LiveQuery
{
$(this).timeago(); // Calling Timeago Funtion
});
});
</script>
//HTML & PHP Code
<?php
$time=time(); // Current timestamp eg: 1371612613
$mtime=date("c", $time); // Converts to date formate 2013-06-19T03:30:13+00:00
?>
You opened this page <a href='#' class='timeago' title="<?php echo $mtime; ?>"></a>
<script type="text/javascript" src="js/jquery.livequery.js"></script>
<script type="text/javascript" src="js/jquery.timeago.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".timeago").livequery(function() // LiveQuery
{
$(this).timeago(); // Calling Timeago Funtion
});
});
</script>
//HTML & PHP Code
<?php
$time=time(); // Current timestamp eg: 1371612613
$mtime=date("c", $time); // Converts to date formate 2013-06-19T03:30:13+00:00
?>
You opened this page <a href='#' class='timeago' title="<?php echo $mtime; ?>"></a>
what about getting the right timezone from the client because when im using that script its showing -2
ReplyDeleteHow can we get the client time?, not the server time? The local client time :)
ReplyDeleteYou opened this page about an hour ago, and it is not refreshing. Google Chrome 27.
ReplyDeletehey, thank you for the tutorial. I just want to know if you can help me to create a market watch on my own.
ReplyDeletethank you
Another great article!... Keep it up Srinivas
ReplyDeletenice jquery plugin, i just knew about this timeago from jquery :D
ReplyDeleteGood work.... It will help me. Thanks for posting.
ReplyDeleteGood stuff
ReplyDeleteSimple and awesomatic.... nice tut...
ReplyDeleteGood work :)
ReplyDeleteThank you!
ReplyDeleteTimeago is awesome!
ReplyDeleteIf you could just implement a "time difference" so that we can substract current time from a time in our database (e.g. a post that has been made 5 minutes ago) and the difference changing live (like on facebook)
ReplyDeleteAwesome wook..... :)
ReplyDeleteNice Stuff
ReplyDeleteas always very good!
ReplyDeleteThe post is pretty interesting. I really never thought I could have a good read by this time until I found out this site.
ReplyDeleteits so helpful. thank you :)
ReplyDeleteMy system is taking future date due to that time difference i got is in negative.
ReplyDeleteSO is there any way for time difference to non-negative and with correct calculation
Thanks you
ReplyDeleteits qualitively helpful
ReplyDeletethanks a lot
By using this we can develop very interactive thing. Nice one.
ReplyDeletenyc article dude :)
ReplyDeletethanks for the tutorial. i am for sure gonna use this on my website
ReplyDeleteAwesome topic. I can't wait for another insightful tips from you. Keep it coming!
ReplyDeleteVery nice article, thanks for sharing.
ReplyDeletenice post
ReplyDeletehow to display details content in php from mysql database using by click on read more button.
ReplyDeletenice work.......
ReplyDeleteGreat blog and thanks for publish..
ReplyDeleteWhy are you using LiveQuery and adding an extra http call to for an additional plugin that's not needed. LiveQuery is already built in to jQuery so that is unnecessary. It used to be .live.() now it is .on(). So you should be using .on() and not a livequery plugin.
ReplyDeleteAhah, I love it!
ReplyDeleteHmmmm..This s wat i need..cooll..!!!!!!!
ReplyDeleteI don't be sorry that spent a few of minutes for reading. Write more often, surely’ll come to read amazing new.
ReplyDeletethank you so much for the post :D very helpfull
ReplyDeletethank you so much
ReplyDeleteThank you
ReplyDelete
ReplyDeleteChat