我正在尝试从下周一00:00到moment.js之间的当前时间倒数秒。
我查看了文档(http://momentjs.com/docs/#/displaying/difference/),但我只是到了下周一以来的日子,这是我尝试进行倒计时工作的代码。知道我做错了什么吗?
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);
}
答案 0 :(得分:2)
var now = moment();
上有拼写错误。将;
替换为,
diff
两次,将第一个更改为其他内容,例如diffSec
nextmonday = moment().day(1).startOf('day').add('days',7)