9lessons programming blog
Loading Search
9lessons Bring Friends
Wall Script
Follow Me:
Thursday, June 20, 2013

Jquery Timeago Implementation with PHP.

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.

Timeaog Jquery PHP.


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="js/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>
Comments
{ 33 comments }
Pablo Lopez said...

what about getting the right timezone from the client because when im using that script its showing -2

Matias said...

How can we get the client time?, not the server time? The local client time :)

Jartaud said...

You opened this page about an hour ago, and it is not refreshing. Google Chrome 27.

Al Kasih said...

hey, thank you for the tutorial. I just want to know if you can help me to create a market watch on my own.

thank you

June domingo said...

Another great article!... Keep it up Srinivas

Rafadev said...

nice jquery plugin, i just knew about this timeago from jquery :D

Marimuthu M said...

Good work.... It will help me. Thanks for posting.

Eddu Mundia said...

Good stuff

Balaji said...

Simple and awesomatic.... nice tut...

moeng_mey said...

Good work :)

Clowen said...

Thank you!

Mark said...

Timeago is awesome!

Dia said...

If 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)

Nikhil said...

Awesome wook..... :)

Abhijit Singh said...

Nice Stuff

MΛᄃZZIПGΣЯ said...

as always very good!

birkin bag said...

The post is pretty interesting. I really never thought I could have a good read by this time until I found out this site.

Service Tax Registration said...

its so helpful. thank you :)

Anonymous said...

My system is taking future date due to that time difference i got is in negative.
SO is there any way for time difference to non-negative and with correct calculation

sohbet said...

Thanks you

Tushar Bhardwaj said...

its qualitively helpful
thanks a lot

Shahid said...

By using this we can develop very interactive thing. Nice one.

Shekhar Goyal said...

nyc article dude :)

Apoorv said...

thanks for the tutorial. i am for sure gonna use this on my website

Kristy of Metrixa Technology said...

Awesome topic. I can't wait for another insightful tips from you. Keep it coming!

sewa mobil said...

Very nice article, thanks for sharing.

Nishant Kondal said...

nice post

Anonymous said...

how to display details content in php from mysql database using by click on read more button.

Anonymous said...

nice work.......

Mobile Application Development said...

Great blog and thanks for publish..

Anonymous said...

Why 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.

Daniil said...

Ahah, I love it!

Sridhar said...

Hmmmm..This s wat i need..cooll..!!!!!!!

Post a Comment