Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  163] [ 3]  / answers: 1 / hits: 80126  / 10 Years ago, sun, may 4, 2014, 12:00:00

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();


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



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


Is there is something like this?


More From » date

 Answers
27

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()


Here is the reference in the docs.


[#71191] Thursday, May 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jelani

Total Points: 473
Total Questions: 99
Total Answers: 99

Location: Cape Verde
Member since Fri, Nov 27, 2020
4 Years ago
;