Work with a time span in Javascript

后端 未结 7 767
感动是毒
感动是毒 2020-11-30 05:53

Using Date.js already, but can also use another library if necessary.

Not sure what is the best way to work with time deltas. Specifically, I want to display the tim

7条回答
  •  忘掉有多难
    2020-11-30 06:14

    You can use momentjs duration object

    Example:

    const diff = moment.duration(Date.now() - new Date(2010, 1, 1))
    console.log(`${diff.years()} years ${diff.months()} months ${diff.days()} days ${diff.hours()} hours ${diff.minutes()} minutes and ${diff.seconds()} seconds`)
    

提交回复
热议问题