2017-02-10 13 views
0

日付をミリ秒単位で出力することを検討していますが、動作しません。getTime()でのミリ秒単位の日付

{{product.date_expiration}}:// WICH出力==> 2018-01-13T12:22:06.165Z

{{CURRENTDATE}}:私はHTMLファイルの

//ウィッヒ出力==> "2017-02-10T13:18:58.339Z" と

date_expiration: {type: Date} 

と:

私はミリ秒単位で日付を取得しようとwhene 10:

{{product.date_expiration.getTime()}} ==>しないのは何も

と出力:

{{CurrentDate.getTime()}} ==> output 1486733469830 

任意のヘルプ感謝されます。 date_expirationがobject.So getTime()機能がit.We上で動作していない日はないようおかげ

+0

date_expirationはおそらく、文字列、日付ではないです。 –

+0

'{{produit.date_expiration.getTime()}}'は質問のタイプミスですか、それともそのタイプミスですか? –

+1

sory、それはタイプミスで、投稿が編集されました – Nassim

答えて

0

たちは、角表現でDate()を使用することはできませんとして&は私たちにミリ秒単位の時間を与えるDateオブジェクトに変換しますフィルタを使用するようにしているようです。

var app = angular.module('myApp', []); 
 
app.filter('inMilliseconds', function() { 
 
    return function(x) { 
 
       
 
     return new Date(x).getTime(); 
 
    }; 
 
}); 
 
app.controller('myCtrl', function($scope) { 
 
    $scope.date_expiration = "2018-01-13T12:22:06.165Z"; 
 
    $scope.currentDate = new Date(); 
 
});
<!DOCTYPE html> 
 
<html> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
 
<body> 
 

 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
date_expiration: {{date_expiration | inMilliseconds }} 
 
<br> 
 
currentDate: {{currentDate.getTime() }} 
 
</div> 
 

 
<script> 
 

 
</script> 
 

 
</body> 
 
</html>

関連する問題