Minutes since midnight in Momentjs

前端 未结 2 1281
野的像风
野的像风 2021-01-03 18:42

In pure JS, this would be how.

How can I find out the number of minutes since midnight for a given moment object (without extracting to Date

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 19:21

    This is what I have at the moment:

        if (!moment.isMoment(mmt)) {
            return 0;
        }
        var hh = mmt.get('hour');
        var mm = mmt.get('minute');
        return hh*60 + mm;
    

    I am not sure if it takes into account various edge cases; comment if this is the case, or provide an alternate answer.

提交回复
热议问题