javascript - Time ago in angular moment js - Stack Overflow

I am using Moment js and Angular Moment js to calculate time ago for my website. Everything is working

I am using Moment js and Angular Moment js to calculate time ago for my website. Everything is working perfectly except one thing. I don't know whether is it possible or not. I checked their humanize() documentation but didn't find anything usefull.

<span am-time-ago="messagedata.created | amFromUnix"></span>

Result: a day ago but i want 1 day ago. Is it possible? If yes how?

I am using Moment js and Angular Moment js to calculate time ago for my website. Everything is working perfectly except one thing. I don't know whether is it possible or not. I checked their humanize() documentation but didn't find anything usefull.

<span am-time-ago="messagedata.created | amFromUnix"></span>

Result: a day ago but i want 1 day ago. Is it possible? If yes how?

Share Improve this question asked Feb 17, 2017 at 8:15 uiTeam324uiTeam324 1,25515 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Check fromnow section from moment it is what you are looking for, since you want to display the date with respect to today.

Those messages depend on the locale used by moment.js but you can update the locale to provide a different version of the messages

moment.updateLocale('en', {
    relativeTime : {
        future: "in %s",
        past:   "%s ago",
        s:  "seconds",
        m:  "a minute",
        mm: "%d minutes",
        h:  "an hour",
        hh: "%d hours",
        d:  "a day",
        dd: "%d days",
        M:  "a month",
        MM: "%d months",
        y:  "a year",
        yy: "%d years"
    }
});

with the angular directive, you should be able to configure the moment instance when the application starts

var myapp = angular.module('myapp', ['angularMoment']);
myapp.run(function(amMoment) {
    amMoment.changeLocale(...);
});

you can check the moment.js documentation about customisation for more details

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

相关推荐

  • javascript - Time ago in angular moment js - Stack Overflow

    I am using Moment js and Angular Moment js to calculate time ago for my website. Everything is working

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信