最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using moment to format time in relation to now - Stack Overflow

programmeradmin1浏览0评论

I'm trying to display a date like "a few seconds ago", "10 minutes ago", "a day ago" with momentjs in the browser.

var date = moment('2017-01-10T13:53:00');
date = moment(date).fromNow();

date returns "in 14 minutes" NOT "14 minutes ago". How can I fix this?

I'm trying to display a date like "a few seconds ago", "10 minutes ago", "a day ago" with momentjs in the browser.

var date = moment('2017-01-10T13:53:00');
date = moment(date).fromNow();

date returns "in 14 minutes" NOT "14 minutes ago". How can I fix this?

Share Improve this question asked Jan 10, 2017 at 18:39 cusejuicecusejuice 10.7k27 gold badges95 silver badges150 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

Because you would have been paring it in that way only. Now should be less than the date to show ago.

    var date = moment('2017-01-11T00:01:00');
    date = moment(date).fromNow();
    console.log(date);

//15 minutes ago

Current Date is "Wed Jan 11 2017 00:16:32 GMT+0530 (IST)"

var date = moment('2017-01-11T01:01:00');
date = moment(date).fromNow();
console.log(date);

//in 44 minutes
发布评论

评论列表(0)

  1. 暂无评论