Add a duration to a moment (moment.js)

后端 未结 3 2010
猫巷女王i
猫巷女王i 2020-11-29 22:10

Moment version: 2.0.0

After reading the docs, I thought this would be straight-forward (Chrome console):

var timestring1 = \"2013-05-09T00:00:00Z\";
         


        
3条回答
  •  温柔的废话
    2020-11-29 22:36

    For people having a startTime (like 12h:30:30) and a duration (value in minutes like 120), you can guess the endTime like so:

    const startTime = '12:30:00';
    const durationInMinutes = '120';
    
    const endTime = moment(startTime, 'HH:mm:ss').add(durationInMinutes, 'minutes').format('HH:mm');
    
    // endTime is equal to "14:30"
    

提交回复
热议问题