简体   繁体   English

如何显示人类可读的“时间前”

[英]How to show human-readable “time ago”

My user last logged in at 15:50:09 Wednesday, January 25, 2012 IST how can i show it as "10 minutes ago". 我的用户上次登录的时间是2012年1月25日(星期三)15:50:09 IST我怎么能把它显示为“10分钟前”。 Is there any js? 有没有js?

I have always used timeago , it is a jQuery plugin, very easy to use. 我一直使用timeago ,它是一个jQuery插件,非常容易使用。 The example in the main page is self-explicative: 主页面中的示例是自解释的:

<script src="jquery.timeago.js" type="text/javascript"></script>
$("abbr.timeago").timeago();

Will convert this markup: 将转换此标记:

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>

into this one: 进入这一个:

<abbr class="timeago" title="July 17, 2008">3 years ago</abbr>

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. 在某些情况下,使用datejs也很有用,特别是如果你想将人类可读格式的日期转换为时间戳,但在你的情况下,我认为你真的不需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM