【发布时间】:2014-01-04 20:59:55
【问题描述】:
我正在尝试使用 moment.js 对自下周一 00:00 以来的当前时间之间的秒数进行倒计时。
我查看了文档 (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);
}
【问题讨论】:
标签: javascript time momentjs