How to Customize Humanized Moment js Date Result

后端 未结 1 331
醉话见心
醉话见心 2021-01-25 09:31

I want to customize the humanize date result with moment js. Let\'s say I have a date and I want to take the remaining time that return back a result \"in 3 months\"

<         


        
相关标签:
1条回答
  • 2021-01-25 10:14

    "Like moment#fromNow, passing true as the second parameter returns value without the suffix. This is useful wherever you need to have a human readable length of time."

    Moment documentation

    So,

    var start = moment([2007, 0, 5]);
    var end = moment([2007, 0, 10]);
    start.from(end);                   // "in 5 days"
    start.from(end, true);             // "5 days"
    start.from(end, true) + " left";   // "5 days left"
    
    0 讨论(0)
提交回复
热议问题