如何使用jquery/javascript格式化时间

mei*_*OrO 2 javascript jquery

我有一个JSON feed,drupal以这种格式吐出时间: 2010-12-16T04:41:35Z

我如何将其格式化为X分钟/小时前?

Dav*_*enn 6

看看timeago jQuery插件,它可以像程序化一样使用

var t = jQuery.timeago("2010-12-16T04:41:35Z"); 
Run Code Online (Sandbox Code Playgroud)

或者像HTML这样的HTML元素

<time class="timeago" datetime="2008-07-17T09:24:17Z">July 17, 2008</time>
<script type="javascript">
  jQuery(document).ready(function() {
    jQuery("time.timeago").timeago();
  });
</script>
Run Code Online (Sandbox Code Playgroud)