如何显示人类可读的“时间之前” [英] How to show human-readable "time ago"
本文介绍了如何显示人类可读的“时间之前”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的用户上次登录时间是2012年1月25日星期三15:50:09 IST
我怎么能把它显示为10分钟前。
有没有js?
My user last logged in at 15:50:09 Wednesday, January 25, 2012 IST how can i show it as "10 minutes ago". Is there any js?
推荐答案
我一直用 timeago ,它是一个jQuery插件,非常易于使用。主页面中的示例是自解释的:
I have always used timeago, it is a jQuery plugin, very easy to use. The example in the main page is self-explicative:
<script src="jquery.timeago.js" type="text/javascript"></script>
$("abbr.timeago").timeago();
将转换此加价:
<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
进入这一个:
<abbr class="timeago" title="July 17, 2008">3 years ago</abbr>
在某些情况下,使用 datejs ,特别是如果你想将人类可读格式的日期转换为时间戳,但在你的情况下,我认为你真的不需要它。
In some cases is useful to also use datejs, specially if you want to convert dates in a human readable format to a timestamp, but in your case I don't think you really need it.
这篇关于如何显示人类可读的“时间之前”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文