How to convert hours and minutes to minutes with moment.js?

前端 未结 5 668
时光说笑
时光说笑 2021-01-01 17:19

I need to convert hours and minutes in minutes values. With pure JavaScript Date object I do the following:

var d = new Date();
var minutes = d.getHours() *          


        
5条回答
  •  一生所求
    2021-01-01 17:36

    I didn't needed moment.js, at least worked for my scenarios:

    console.log('converting 2 hours, 20 minutes and 120 seconds to minutes');
    
    var hours = 2,
      minutes = 20,
      seconds = 120,
      timeInminutes = (hours * 60) + minutes + (seconds / 60);
    
    console.log('2 hours, 20 minutes and 120 seconds to minutes is', timeInminutes, ' minutes')

提交回复
热议问题