如何用moment.js将小时和分钟转换为分钟?

问题描述:

我需要以分钟为单位转换小时和分钟值。使用纯JavaScript Date对象,我执行以下操作:

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() * 60 + d.getMinutes();

我刚刚切换到 moment.js 并寻找更好的解决方案,如下所示:

I've just switched to moment.js and looking for better solution likes the following:

var minutes = moment(new Date()).toMinutes()

是否有这样的东西?

我认为你最好的办法是创建持续时间,然后使用获取会议记录asMinutes 。在描述时间间隔时,这可能更清楚。

I think your best bet is to create a Duration and then get the minutes using asMinutes. This is probably clearer when describing an interval of time.

moment.duration().asMinutes()

以下是文档中的参考资料