I'm trying to make a countdown of seconds between the current time since next Monday 00:00 with moment.js.
I have looked at the documentation (http://momentjs.com/docs/#/displaying/difference/) but I only arrived to have the days since next Monday, this is the code I try to make work to have the countdown. Any idea what I'm doing wrong?
var datetime = $('.datetime'),
//Update countdown
update = function(){
var now = moment();
nextmonday = moment().day(1),
diff = now.diff(nextmonday, 'seconds'),
hours = Math.floor(diff / 3600),
diff = diff - hours * 3600,
minutes = Math.floor(diff / 60),
seconds = diff - minutes * 60;
datetime.html(diff);
};
//If it's Monday do nothing
if (moment().day()!=1){
update();
setInterval(update, 1000);
}
var now = moment();. Replace ; with ,diff twice, change the first one to something else like diffSecnextmonday = moment().day(1).startOf('day').add('days',7)Working example: http://jsfiddle.net/jondlm/x4MM6/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With