My date from the database table looks like this:
我在数据库表中的日期是这样的:
"2017-12-07 14:42:38.0611177 +00:00"
“2017-12-07 14:42:38.0611177 + 00:00”
I'm trying to format it in my HTML like this:
我想把它格式化成这样:
<td>{{ note.CreatedAt | date : "MMM d, y" }}</td>
< td > { {注意。日期:“MMM d, y”}
I was expecting the date to look like this:
我原以为约会会是这样的:
Dec 7, 2017
2017年12月7日
But, the result looks like this:
但是,结果是这样的:
Can someone show me what I'm doing wrong?
有人能告诉我我做错了什么吗?
1 个解决方案
#1
2
You have to convert your date as a timestamp before filter it.
您必须将您的日期转换为时间戳,然后再进行过滤。
Aleksey remark is a good point, you can get timestamp from controller:
Aleksey是一个很好的观点,您可以从controller获得时间戳:
angular.module('app').controller('dateCtrl', ['$scope', function($scope){
var date = "2017-12-07 14:42:38.0611177 +00:00";
$scope.createdAt = new Date(date).valueOf();
}]);
And use it in your view:
并在你的观点中使用它:
<span>{{createdAt | date : "MMM d, y"}}</span>
Top example will output: Dec 7, 2017
顶部示例将输出:2017年12月7日
恰好演示
For more informations, refer to AngularJS documentation concerning [date filter].2
有关更多信息,请参阅有关[日期过滤器].2的AngularJS文档
#1
2
You have to convert your date as a timestamp before filter it.
您必须将您的日期转换为时间戳,然后再进行过滤。
Aleksey remark is a good point, you can get timestamp from controller:
Aleksey是一个很好的观点,您可以从controller获得时间戳:
angular.module('app').controller('dateCtrl', ['$scope', function($scope){
var date = "2017-12-07 14:42:38.0611177 +00:00";
$scope.createdAt = new Date(date).valueOf();
}]);
And use it in your view:
并在你的观点中使用它:
<span>{{createdAt | date : "MMM d, y"}}</span>
Top example will output: Dec 7, 2017
顶部示例将输出:2017年12月7日
恰好演示
For more informations, refer to AngularJS documentation concerning [date filter].2
有关更多信息,请参阅有关[日期过滤器].2的AngularJS文档