我有
const endTime = moment().format("HH:mm:ss");
const duration = moment.utc(request.input('duration') * 60000).format("HH:mm:ss");
我想计算
startTime = endTime - duration
答案 0 :(得分:1)
endTime.subtract(duration);
如果你想深入挖掘docs
,那么这就是文档编辑:
const endTime = moment(); //now time
const duration = request.input('duration') //duration in miliseconds
let startTime = endTime.subtract(duration,'ms')
const endTime = moment(); //now time
const duration = 600000; //hardcoded 10 mins //duration in miliseconds
let startTime = endTime.subtract(duration, 'ms')
console.log(endTime)
console.log(startTime)

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>
&#13;
答案 1 :(得分:1)
您可以使用endTime.subtract(duration,'ms')。但是对于那个结束时间必须是一个时刻的对象。所以稍后格式化答案。
const endTime = moment();
const duration = request.input('duration')
let startTime = endTime.subtract(duration,'ms').format('HH:mm:ss')