如何用moment.js将小时和分钟转换为分钟? [英] How to convert hours and minutes to minutes with moment.js?

查看:1708
本文介绍了如何用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()

以下是文档中的参考资料

这篇关于如何用moment.js将小时和分钟转换为分钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆