stackoverflow-240842
https://pt.stackoverflow.com/questions/240842/contagem-regressiva-incluir-m%c3%aas
by Wellington Moreira
HTML
<script src="https://momentjs.com/downloads/moment.js"></script>
<body>
<div id="div">
</div>
</body>
JavaScript
var getCountDownBetween = function (from, to) {
// Find the distance between now an the count down date
var distance = moment.duration(to.diff(from));
// Time calculations for days, hours, minutes and seconds
return {
months: distance.months(),
days : distance.days(),
hours : distance.hours(),
minutes : distance.minutes(),
seconds : distance.seconds(),
toString: function() {
return this.months + 'mo '
+ this.days + "d "
+ this.hours + "h "
+ this.minutes + "m "
+ this.seconds + "s ";
}
};
}
//Test functions
var appendHTML = function (str) {
document.getElementById('div').innerHTML += '</br>' + str;
}
//Test
appendHTML(getCountDownBetween(moment(), moment()));
appendHTML(getCountDownBetween(moment('2017-09-06T16:33:09'), moment('2017-09-20T23:52:33')));
appendHTML(getCountDownBetween(moment('2017-01-01T20:09:09'), moment('2017-07-11T00:51:00')));