Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MomentJs convert milliseconds to days

Tags:

momentjs

I am new to moment.js. I want to convert milliseconds to days. When I tried in normal converter in google it is showing 377.7613437963 days, but programatically it is showing 11 days.

var duration = moment.duration(32638528433, 'milliseconds');
var days = duration.days();
console.log(days);
like image 271
Kodanda Rama Durgarao Poluri Avatar asked Mar 20 '17 10:03

Kodanda Rama Durgarao Poluri


1 Answers

You need to use asDays() if you want 377.7613437963 as output.

As the docs says:

As with the other getters for durations, moment.duration().days() gets the days (0 - 30).

moment.duration().asDays() gets the length of the duration in days.

Here a live example:

var duration = moment.duration(32638528433, 'milliseconds');
var days = duration.asDays();
console.log(days);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
like image 69
VincenzoC Avatar answered Sep 28 '22 09:09

VincenzoC