本文介绍了从Momentjs午夜开始的分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在纯JS中,将是如何。
In pure JS, this would be how.
如何找出自午夜以来给定的时间
对象(不提取到 Date
)的分钟数?
How can I find out the number of minutes since midnight for a given moment
object (without extracting to Date
)?
- 必须考虑到DSTs
- 分数应舍入
- 必须与当地时间一起工作(不能转换为UTC)
推荐答案
// Your moment
var mmt = moment();
// Your moment at midnight
var mmtMidnight = mmt.clone().startOf('day');
// Difference in minutes
var diffMinutes = mmt.diff(mmtMidnight, 'minutes');
默认情况下,moment#diff将返回向下舍入的数字。如果您想要浮点数,则作为第三个参数传递为true。在2.0.0之前,moment#diff返回四舍五入的数字,而不是四舍五入的数字。
By default, moment#diff will return number rounded down. If you want the floating point number, pass true as the third argument. Before 2.0.0, moment#diff returned rounded number, not a rounded down number.
考虑这个伪代码,因为我没有测试是否考虑到差异DST。
Consider this pseudocode because I haven't test to see if the difference takes into account DST.
这篇关于从Momentjs午夜开始的分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!