admin管理员组文章数量:1431002
I am using moment.js "timeAgo" to display some dates. But I only want to use moment.js if the date is within the last week. (7 days ago) After that point I would just like to display the date as normal. Example: (Jun 20, 2010) instead of (3 years ago).
I have the defaults working with this code. Any help would be great.
var date = moment.unix(<?php echo $date; ?>).fromNow();
$("#date").append(date);
I am using moment.js "timeAgo" to display some dates. But I only want to use moment.js if the date is within the last week. (7 days ago) After that point I would just like to display the date as normal. Example: (Jun 20, 2010) instead of (3 years ago).
I have the defaults working with this code. Any help would be great.
var date = moment.unix(<?php echo $date; ?>).fromNow();
$("#date").append(date);
Share
Improve this question
edited Jun 20, 2013 at 18:41
Staysee
asked Jun 20, 2013 at 17:05
StayseeStaysee
1,9075 gold badges23 silver badges30 bronze badges
1 Answer
Reset to default 7var 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());
}
本文标签: javascriptMomentjs only within the last weekStack Overflow
版权声明:本文标题:javascript - Moment.js only within the last week - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745466481a2659554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论