Problem
I want a timer that will accept the seconds, minutes, hours, days and start incrementing from there, say user open a page where the time fetched from server is say 2 hours 30 minutes 05 seconds
, now the javascript timer will start incrementing from this so it 02:30:05
then 02:30:06 .. 02:31:00
and so on.. as soon as seconds reach 60 minute is incremented
What I have tried
I have implemented the same using moment.js
var duration = moment.duration({
'seconds': 30,
'hour': 2,
'minutes': 10
});
var interval = 1;
setInterval(function () {
duration = moment.duration(duration.asSeconds() + interval, 'seconds');
//.asSeconds()
$('.countdown').text(Math.round(duration.asHours()) + 'h:' + Math.round(duration.asMinutes()) + 'm:' + Math.round(duration.asSeconds()) + 's'); //.seconds()
$('.countdown1').text(duration.days() + 'd:' + duration.hours() + 'h:' + duration.minutes() + 'm:' + duration.seconds() + 's');
}, 1000);
Requirement
I want to know how i can implement it using javascript/jquery if possible else I will use moment.js
one, I have looked around but all have countdown timer created from date, so the input will be seconds, minutes, hours, days
and the counter will start from there in increment manner