Any one tell me how to filter date from json date format. I want to disply like eg,wed, 07 Mar 2018.
My code is,
<p>{{item.date}}</p>
my json is,
"date": "Wed, 07 Mar 2018 00:00:00 PST",
Any one tell me how to filter date from json date format. I want to disply like eg,wed, 07 Mar 2018.
My code is,
<p>{{item.date}}</p>
my json is,
"date": "Wed, 07 Mar 2018 00:00:00 PST",
Apply a date filter with your requirements for the format:
var app = angular.module('myApp', []);
app.controller('datCtrl', function($scope) {
var json = {
"date": "Wed, 07 Mar 2018 00:00:00 PST"
};
$scope.item = new Date(json.date);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp" ng-controller="datCtrl">
<p>{{ item | date: 'dd MMM y'}}</p>
</div>
Note that you need to cast a date type to it first: new Date()
use pipe "|" here is the link to the documentation https://docs.angularjs.org/api/ng/filter/date
you have to use the angularjs filter date passing the correct format, in your case the format is 'dd MMM yyyy'.
<p>{{item.date | date: 'dd MMM yyyy'}}</p>
And also you have to transform your date in a valid javascript address:
$scope.item.date = new Date($scope.item.date);