stormec56 stormec56 - 1 month ago 9
AngularJS Question

How to Exclude Hours, Minutes and Seconds in AngularJS Date?

I'm receiving data from

JSON
file via
$http.get
request. In my JSON file this is the format I receive:

"date": "2016-10-24 15:14:53"


I want to format it to be like this:
October 10 2016
(without
hh-mm-ss
)

My code:

<body data-ng-app="myApp">

<div data-ng-controller="alfaCtrl1" class="blogwrapper" id="blogFirst">
<span>{{date}}</span><span></span>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get('jsonfile.json').success(function(data) {
$scope.date = data.posts[0].date;
});
});
</script>
</body>


This question is different from the one proposed as "duplicate", since it expands the process to Angular way of formatting date.

Answer
var formateDate = new Date(data.posts[0].date)
$scope.date = $filter('date')(formateDate, 'longDate');