asp.net mvc时间前用单词helper [英] asp.net mvc time ago in words helper
本文介绍了asp.net mvc时间前用单词helper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如何计算相对时间?
Possible Duplicate:
How do I calculate relative time?
是否有与asp.net MVC的rails的time_ago_in_words帮助器类似的东西?
Is there anything similar to rails' time_ago_in_words helper for asp.net MVC?
推荐答案
取决于您的预期输出目标,jQuery插件 Timeago 可能是一个更好的选择.
Depending on your intended output target, the jQuery plugin Timeago may be a better option.
这是一个HtmlHelper,用于创建包含 ISO 8601 时间戳记的<abbr />
元素:
Here's an HtmlHelper to create an <abbr />
element containing an ISO 8601 timestamp:
public static MvcHtmlString Timeago(this HtmlHelper helper, DateTime dateTime) {
var tag = new TagBuilder("abbr");
tag.AddCssClass("timeago");
tag.Attributes.Add("title", dateTime.ToString("s") + "Z");
tag.SetInnerText(dateTime.ToString());
return MvcHtmlString.Create(tag.ToString());
}
在页面上的某处用以下JavaScript组合上面的帮助程序的输出,您就会有钱.
Combine the above helper's output with the following JavaScript somewhere on your page and you'll be in the money.
<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery.timeago.js" type="text/javascript"></script>
jQuery(document).ready(function() {
jQuery("abbr.timeago").timeago();
});
这篇关于asp.net mvc时间前用单词helper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文