Livestamp插件Jquery-如何显示时间
Livestamp Plugin Jquery - how to show a time?
我使用这个jquery插件:livestamp。如果您知道,请告知如何仅显示当天的时间(小时,分钟前)。第二天24小时后-显示标签"昨天"或简单的日期。非常感谢。
默认情况下,我认为livestamp无法做到这一点。
但是,在livestamp示例的底部,他们有一些代码可以在文本更改时通过挂接到change.livestamp
事件来设置动画。
我们可以使用moment.js来修改此代码,以满足您的要求。
$('#animation').on('change.livestamp', function(event, from, to) {
event.preventDefault(); // Stop the text from changing automatically
// Get the original timestamp out of the event
var originalTS = event.timeStamp;
// Make a new moment object to compare the timestamp to
var newDate = moment();
// Use moment's .diff method to get the ms difference between timestamps
var delta = newDate.diff(originalTS);
// If the difference is less than a day's worth of ms
if (delta < 86400000){
// Use formatted text provided by the change event
$(this).html(to);
}
else {
// Format the moment object with whatever moment format you want
$(this).html( newDate.format("dddd M/D/YYYY") );
}
}).livestamp();
我还没有使用livestamp,但它的格式选项似乎依赖于现有的moment,所以这应该很有效。
Livestamp的源代码非常小,所以如果你有其他想做的事情,可以考虑自己破解它。
相关文章:
- 显示时间的脚本
- 如何用前导零显示时间
- 如何在烛光图表中添加/显示时间框架
- 如何在页面上显示时间、日期IP和URL?更新日期:2015年2月25日
- 在条件中的几个时间行中设置自定义css效果后,从Jquery时间选择器显示时间
- 在指定时间中添加 24 小时后在网页上显示时间 x
- 如何像这样显示时间,例如:1秒前,1分钟前,1小时前,1个月前
- j查询日期选取器不显示时间输入值
- JavaScript 和 JQuery:在文本框中显示时间
- 给定一个时间戳,如何按天/周/月显示时间
- 为什么不显示时间
- 显示时间而不是日期的图表
- 根据天数和月数显示时间戳
- 如何在 Javascript 中显示时间
- 如果午夜使用时刻.js,则不显示时间
- 是否可以筛选 JSON 源以仅显示时间戳字符串中的时间
- 检查后显示时间选择器复选框,导轨(Redmine)
- 设置showErrorMessage()的显示时间
- 以12小时格式显示时间
- 日期时间倒计时,删除小数,并在每个类别中保留时间显示时间