开发者

timeago Jquery Plugin Date Format Problem

开发者 https://www.devze.com 2023-02-10 13:49 出处:网络
Here we go:I\"m trying to implement the timeago jquery plugin (http:开发者_开发技巧//timeago.yarp.com/) on my project to show relative time (.i.e \"2mins ago\" instead of \"1.10pm\").I have a field in

Here we go: I"m trying to implement the timeago jquery plugin (http:开发者_开发技巧//timeago.yarp.com/) on my project to show relative time (.i.e "2mins ago" instead of "1.10pm"). I have a field in my MySQL database which stores the timestamp of the current entry.

However, the timeago jquery plugin only works when the time is in UTC format "2008-07-17T09:24:17Z"

My first problem is: How to convert mysql timestamp to the above required format. My second problem: Even when I hardcode the required format in my code, the plugin does not work. Why?

My hardcode: In php file 1:

echo '<abbr class="timestamp" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>';

In index.php file 2

$("abbr.timestamp").timeago();

Of course, I've included the script tag properly. I can't figure out why it's not working. Note: I'm working on XAMPP, on my own computer (local).


  1. echo date(DATE_ISO8601, strtotime('2011-02-16 12:26:00'));
  2. Are you executing timeago when the DOM has finished loading? I.e.:

    jQuery(function ($) {
        $("abbr.timestamp").timeago();
    }
    


$time=time(); // Current timestamp eg: 1371612613
$formatted_time=date("c", $time); // Converts to date format 2014-09-12T02:30:13+00:00

js code

jQuery(function ($) {
    $("abbr.timestamp").timeago();
}


This plugin worked with mysql default timestamp in case of mine. put your timestamp in the title.Try this once:

<script type="text/javascript">
jQuery(document).ready(function($) {

      jQuery("div.myRelativeTimestamp").timeago();
})
</script>
<div class="myRelativeTimestamp" title="<?php echo $row->time; ?>"></div>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号