When displaying a date value in your view, you can utilize the date filter.
Ensure that your HTML code includes both the variable and the filter:
<div ng-app="app" ng-controller="MyCtrl">
<p>{{time | date:'yyyy-MM-dd HH:mm:ss'}}</p>
</div>
In your JavaScript file, create a date object from a string literal to format the date according to the browser's local time:
var app = angular.module('app', []);
app.controller('MyCtrl', function ($scope, $filter) {
var jsonvalue = '2015-08-12T05:00:00.000Z';
$scope.time = new Date(jsonvalue);
$scope.parsed = $filter('date')($scope.time, "yyyy-MM-dd HH:mm:ss");
});
You can also use the filter module within your controller to parse dates. In the provided example, the parsed
variable will store the correctly formatted date as a string.
For a working demonstration, check out this fiddle: http://jsfiddle.net/9pd7rbur/2/