我发现了一个很酷的Momentjs库,但是我觉得文档对如何实现一些简单任务不是很清楚。我想要构建一个倒计时器,猜测应该使用duration对象,但我不太明白如何做(可能是因为英语不是我的母语)。总之这就是我想要的:
var time = 7200;
var duration = moment.duration('seconds',time);
setInterval(function(){
//show how many hours, minutes and secods are left
$('.countdown').text(duration.format('h:mm:ss'));
//this doesn't work because there's no method format for the duration object.
},1000);
每秒钟都应该显示:
02:00:00
01:59:59
01:59:58
01:59:57
...
00:00:00
如何使用Momentjs库实现这个结果?谢谢!
setInterval
。 - pimvdb