最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Convert minutes to days, hours and minutes using moment js - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question edited Sep 7, 2020 at 6:03 Saniya syed qureshi 3,1773 gold badges18 silver badges23 bronze badges asked Sep 7, 2020 at 5:56 Wasana RanasingheWasana Ranasinghe 411 silver badge8 bronze badges 1
  • Is there a reason you need to use Momentjs and not plain Javascript? – JHeth Commented Sep 7, 2020 at 6:07
Add a ment  | 

1 Answer 1

Reset to default 9

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.

发布评论

评论列表(0)

  1. 暂无评论