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

I'm trying to display a date like "a few seconds ago", "10 minutes ago", "

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745585990a4634543.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信