Convert minutes to days, hours and minutes using moment js

烈酒焚心 提交于 2021-02-11 05:01:52

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/63772083/convert-minutes-to-days-hours-and-minutes-using-moment-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!