admin管理员组文章数量:1023529
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?
1 Answer
Reset to default 6Because 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
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?
1 Answer
Reset to default 6Because 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
本文标签: javascriptUsing moment to format time in relation to nowStack Overflow
版权声明:本文标题:javascript - Using moment to format time in relation to now - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745585987a2157598.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论