-1

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",
swetha
  • 65
  • 11
  • 1
    Possible duplicate of [How to format date in angularjs](https://stackoverflow.com/questions/22392328/how-to-format-date-in-angularjs) – lin Mar 15 '18 at 11:21
  • Have you try to search before asking? This question has been solved dozens of times. – lin Mar 15 '18 at 11:24

3 Answers3

2

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()

Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
0

use pipe "|" here is the link to the documentation https://docs.angularjs.org/api/ng/filter/date

0

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);
Josito
  • 374
  • 2
  • 9