我有一个 JSON 文件,以这种格式返回多个日期:

/Date(1235548800000)/

我如何在控制器中过滤它以仅返回年份?

我努力了:

 var filteredDate = $filter('date')($scope.ToDate, 'yyyy');

 console.log(filteredDate);

但控制台显示:

/Date(1235548800000)/
有帮助吗?

解决方案

你可以尝试这个

var parsedDate = new Date(parseInt($scope.ToDate.substr(6)));
var filteredDate = $filter('date')(parsedDate, 'yyyy');
.

其他提示

检查我的 普朗克. 。您应该从以下位置获取时间戳 ToDate 细绳。如果所有时间日期都具有相同的格式,则可以使用类似的方法。

var dt=$scope.toDate.substring($scope.toDate.indexOf("(")+1,$scope.toDate.indexOf(")"));

试试:

var filteredDate = YourDate.getFullYear();
console.log(filteredDate);
.

希望它有助于...........!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top