Sunday, November 26, 2017

Jquery Timeago Plugin Implementation using PHP.

timeago: a jQuery plugin

Timeago is a JQuery plugin that provides a easy way to integrate timestamp update functionality in web based application. Nowadays Timeago Plugin is the most important functionality in social networking sites, it helps to update the timestamps automatically at specific interval of time.

In this post we will going to learn how to integrate timeago Jquery plugin in web application with the help of PHP.

Why Timeago plugin ?
  1. It's support the page caching in your web applications.
  2. Automatically refresh the page and update the timestamp in web application.
  3. Support the HTML5 tags.
  4. Easy to integrate in web applications.

Lets see the below example for Timeago :
index.php
<html>
<head>
<script src="jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="jquery.timeago.js" type="text/javascript"></script>
<script>
jQuery(document).ready(function() {
  jQuery(".timeago").timeago();
});
</script>
</head>
<body>
<?php
$time=time(); // Current timestamp eg: 1371612613
$formatedTime=date("c", $time); // Converts to date formate 2017-06-19T03:30:13+00:00 
?>

<h1> You opened this page <a href='#' class='timeago' title="<?php echo $formatedTime; ?>"></a> </h1>

<h1> This page was last modified <a href='#' class='timeago' title="2017-07-17T14:06:04Z"></a> </h1>

NOTE : This will update every minute. Wait for it.

</body>
</html>

Output :
When you run above page for first time, then it will show below page as output  :
timeago: a jQuery plugin
See the results for last four minutes :

timeago: a jQuery plugin



No comments:

Post a Comment