Angularjs getTime()的日期(毫秒)
我希望以毫秒为单位输出日期,但它不起作用 在HTML文件中,我有: {{product.date_expiration}}://哪个输出==>2018-01-13T12:22:06.165Z {{CurrentDate}}://哪个输出==>“2017-02-10T13:18:58.339Z” 与: 以及: 当我尝试以毫秒为单位获取日期时: {{product.date\u expiration.getTime()}=>不输出任何内容 以及:Angularjs getTime()的日期(毫秒),angularjs,Angularjs,我希望以毫秒为单位输出日期,但它不起作用 在HTML文件中,我有: {{product.date_expiration}}://哪个输出==>2018-01-13T12:22:06.165Z {{CurrentDate}}://哪个输出==>“2017-02-10T13:18:58.339Z” 与: 以及: 当我尝试以毫秒为单位获取日期时: {{product.date\u expiration.getTime()}=>不输出任何内容 以及: 似乎date\u expiration不是一个日期对
似乎
date\u expiration
不是一个日期对象。因此getTime()
函数对它不起作用。我们必须使用一个过滤器将其转换为日期对象,并给我们以毫秒为单位的时间,因为我们不能在角度表达式中使用date()
var-app=angular.module('myApp',[]);
app.filter('inmillizes',function(){
返回函数(x){
返回新日期(x).getTime();
};
});
应用程序控制器('myCtrl',函数($scope){
$scope.date_expiration=“2018-01-13T12:22:06.165Z”;
$scope.currentDate=新日期();
});代码>
date_expiration:{{date_expiration}以毫秒为单位}
currentDate:{{currentDate.getTime()}}
date\u expiration可能是字符串,而不是日期。{{{produit.date\u expiration.getTime()}
是问题中的一个输入错误,还是该输入错误是问题的原因!?抱歉,这是个打字错误,这篇文章被编辑了
date_expiration: {type: Date}
{CurrentDate}}: {type: Date}
{{CurrentDate.getTime()}} ==> output 1486733469830