第一次使用moment.js
和我正在努力实现一个时钟来显示在CET和PST中的时间。我的代码如下:
function cetClock() {
var cet = moment.tz("Europe/London");
var today = new Date(cet);
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkCetTime(m);
s = checkCetTime(s);
$rootScope.cetTime = h + ":" + m + ":" + s;
var t = setTimeout(cetClock, 300);
}
function checkCetTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
cetClock()
<div class="col-md-6">
<p>CET: {{$root.cetTime}}</p>
</div>
我的问题是,视图中的时间只是每4-5秒更新一次。如果我在函数中记录h
、m
、s
,它每500毫秒显示一次更新时间。
问题
为什么表中的时钟每秒钟都没有更新?
发布于 2017-09-22 15:10:14
我建议使用$timeout
而不是自动触发摘要周期的setTimeout
。
https://stackoverflow.com/questions/46367847
复制相似问题