js通过Moment.js让数值秒值和时分秒格式相互转化
1、把时分秒格式转化为数值型的秒值
<script src="https://momentjs.com/downloads/moment.js"></script>
<script>
let time=moment.duration('01:01:01').as('seconds')
console.log(time) //3661
</script>
2、把数值型的秒值转化为时分秒格式
<script src="https://momentjs.com/downloads/moment.js"></script>
<script>
let time = moment.duration(3661, 'seconds') //得到一个对象,里面有对应的时分秒等时间对象值
let hours = time.hours()
let minutes = time.minutes()
let seconds = time.seconds()
console.log(moment({h:hours, m:minutes, s:seconds}).format('HH:mm:ss'))
//01:01:01
</script>