慕慕森
如果你只想要秒数(diff)为什么不使用带有测量参数的 momentjs 的 diff 函数(支持的是years,,,,,,,默认是毫秒monthsweeksdayshoursminutesseconds。)var a = moment([2007, 0, 29]);var b = moment([2007, 0, 28]);a.diff(b, 'days') // 1let dateStart = moment([2020, 9, 2, 12, 0, 0, 125]);let futureTime = moment(); let secondsAgo = (futureTime.diff(dateStart, 'seconds') % 60);let minutesAgo = (futureTime.diff(dateStart, 'minutes') % 60);let hoursAgo = futureTime.diff(dateStart, 'hours');console.log('hour: ' + hoursAgo + ', minute: ' + minutesAgo + ', seconds: ' + secondsAgo)let hms = moment({ hour: hoursAgo, minute: minutesAgo, seconds: secondsAgo});console.log(hms.format('HH:mm:ss'));<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.0/moment.min.js"></script>