Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert minutes to days, hours and minutes using moment js

I am using moment js to convert minutes in to days, hours and minutes

moment.utc().startOf('year').add({ minutes: timeInMinute }).format('D [Days and ]HH[ Hours and ]mm');

(timeInMinute is my input variable) this is work fine for hours and minutes, but when the input value is 1441 it gives,

2 Days and 00 Hours and 01 Minutes.

it should really be 1 Days and 00 Hours and 01 minutes.

What am I doing wrong? please help me

like image 888
Wasana Ranasinghe Avatar asked Oct 19 '25 08:10

Wasana Ranasinghe


1 Answers

You can use moment.duration to calculate hours, days, minutes etc from a time duration:

var duration = moment.duration(1422, 'minutes');

Then you can do:

duration.days();

or

duration.hours();

Here is the official documentation

Note: Please read the project status at the top of the above official link.

like image 76
kewlashu Avatar answered Oct 21 '25 23:10

kewlashu