Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angulajs中添加间隔时间。?_Javascript_Html_Angularjs_Momentjs - Fatal编程技术网

Javascript 如何在angulajs中添加间隔时间。?

Javascript 如何在angulajs中添加间隔时间。?,javascript,html,angularjs,momentjs,Javascript,Html,Angularjs,Momentjs,我正在实现模拟和数字时钟,但问题是,时间并没有显示实时时间,如何设置时间间隔以每秒刷新时间 $scope.TimeZ = moment().format('MMMM Do YYYY, h:mm:ss a'); function TimeZoneDetails(time, date, content, name) { this.Time = time; this.Date = date; this.Content = content; this.Name = nam

我正在实现模拟和数字时钟,但问题是,时间并没有显示实时时间,如何设置时间间隔以每秒刷新时间

$scope.TimeZ = moment().format('MMMM Do YYYY, h:mm:ss a');
function TimeZoneDetails(time, date, content, name) {
    this.Time = time;
    this.Date = date;
    this.Content = content;
    this.Name = name;
}
$scope.LstTimeZoneDetails = [];

$($scope.TimeZone.split(", ")).each(function (key, value) {
    var objTimeZoneDetails = new TimeZoneDetails(moment.tz(value).format('LT'),
        moment.tz(value).format('LL'),
        moment.tz.zone(value).abbr(moment.utc().valueOf()),
        moment.tz.zone(value).name);
    //push values to array
    $scope.LstTimeZoneDetails.push(objTimeZoneDetails);
    timedUpdate();
})

角度本身没有间隔,可以使用

var intervalID = window.setInterval(myCallback, 1 * 1000);

function myCallback() {
  console.log('Time');
}
将“1”替换为您想要的时间。 目前,间隔设置为1秒

破坏或停止间隔使用

clearInterval(intervalID);

角度本身没有间隔,可以使用

var intervalID = window.setInterval(myCallback, 1 * 1000);

function myCallback() {
  console.log('Time');
}
将“1”替换为您想要的时间。 目前,间隔设置为1秒

破坏或停止间隔使用

clearInterval(intervalID);
从AngularJS开始

你需要的是:
$timeout([fn],[delay],[invokeApply],[Pass])

就你而言:

// Set the delay in milliseconds: 1000ms = 1s
var delayInterval = 1000;

// A function to update the time
function updateTime() {
    // Some code to update time...
}

// Pass the updateTime function as first parameter and the deplayInterval as the second parameter to the AngularJS $timeout function.
$timeout(updateTime, delayInterval);
updateTime()
函数中,您可以将要执行的代码(无论您需要什么)按间隔放入,然后您的
updateTime()
函数将在
delayInterval
毫秒内调用。

自AngularJS起

你需要的是:
$timeout([fn],[delay],[invokeApply],[Pass])

就你而言:

// Set the delay in milliseconds: 1000ms = 1s
var delayInterval = 1000;

// A function to update the time
function updateTime() {
    // Some code to update time...
}

// Pass the updateTime function as first parameter and the deplayInterval as the second parameter to the AngularJS $timeout function.
$timeout(updateTime, delayInterval);

updateTime()
函数中,您可以将要执行的代码(您需要的任何代码)按间隔放置,然后您的
updateTime()
函数将每
delayInterval
毫秒调用一次。

您需要将时间更改为特定时区吗?您可以使用momentjs库作为时区。是的,我正在使用momentjs,虽然时间没有更新。您需要将时间更改为特定的时区?您可以使用momentjs库进行时区设置。是的,我正在使用that moment.js,虽然时间不在更新hanks,但我需要为上面的脚本设置时间间隔。如何设置?我尝试了你的代码,它在正常情况下工作,但是上面的脚本没有显示,但是我需要为上面的脚本设置间隔,如何?我试过你的代码在正常情况下工作,但上面的脚本没有显示