2016-11-07 4 views
0

Date()。getTime()から数値を取得するクリック機能があります。私はこの数字を取って、私の見解でカウントダウンで彼を変換したい。Date()。getTime()からJavascriptでカウントダウンを作成するにはどうすればよいですか?

私はIonicフレームワーク1xでjavascriptのみを使用しています。

var currentDate = new Date().getTime(); 
console.log(currentDate); 

var secondDate = new Date(item.date).getTime(); 
console.log(secondDate); 
secondDate = new Date(secondDate).getSeconds(); 
console.log(secondDate); 
$scope.countdown = secondDate; 

答えて

1

プレーンJavaScriptでは、あなたがこのようsetIntervalを利用することができます:

setInterval(function() { 
 
    console.log(new Date().getTime()); 
 
}, 1000);

イオン/角度では、ラッパー$intervalsetIntervalを交換する必要があります

$interval(function() { 
    $scope.countdown = new Date().getTime(); 
}, 1000); 
+0

ありがとうございますczosel!それは完璧に働いています。時間については、カウントダウンを元に戻す簡単な方法がありますか? –

+0

よろしくお願いします!カウントダウンを元に戻すには、現在の日付とカウントダウンしている日付の差を計算し、その値をスコープにバインドします。 –

0

試行:

var interval = setInterval(function() { 
$scope.countdown -= 1; 
    if ($scope.countdown == 0) { 
     clearInterval(interval); 
    } 
},1000); 
関連する問題