How can I humanize this complete duration in moment.js / javascript

后端 未结 4 1929
遇见更好的自我
遇见更好的自我 2020-12-03 15:05

I have a \'time remaining\' counter in place for file uploads. The remaining duration is calculated and converted into milliseconds like so:

var elapsedTime         


        
4条回答
  •  囚心锁ツ
    2020-12-03 15:37

    My HumanizeDuration.js library sounds like exactly what you want:

    humanizeDuration(1);         // "1 millisecond"
    humanizeDuration(3000);      // "3 seconds"
    humanizeDuration(2012);      // "2 seconds, 12 milliseconds"
    humanizeDuration(97320000);  // "1 day, 3 hours, 2 minutes"
    

    Looks like my answer's a bit late, but maybe it'll help others looking at this question!

提交回复
热议问题