[英]Moment.js only within the last week
I am using moment.js "timeAgo" to display some dates. 我正在使用moment.js“timeAgo”来显示一些日期。 But I only want to use moment.js if the date is within the last week.
但是如果日期在上周内,我只想使用moment.js。 (7 days ago) After that point I would just like to display the date as normal.
(7天前)在那之后我只想正常显示日期。 Example: (Jun 20, 2010) instead of (3 years ago).
例如:(2010年6月20日)而不是(3年前)。
I have the defaults working with this code. 我有使用此代码的默认值。 Any help would be great.
任何帮助都会很棒。
var date = moment.unix(<?php echo $date; ?>).fromNow();
$("#date").append(date);
var someDate = moment.unix(<?php echo $date; ?>);
if(moment().diff(someDate, 'days') > 7){
$("#date").append(someDate.format("dddd, MMMM Do YYYY"));
} else {
$("#date").append(someDate.timeAgo());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.