Skip to content

Commit

Permalink
JSON Date Filter
Browse files Browse the repository at this point in the history
JSON Date Filter exmaple
  • Loading branch information
techieshravan committed Jul 9, 2015
1 parent 12c94eb commit 2169260
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions JSONDateFilter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>

<head>
<title>Angular JSON Date Converter Filter Example</title>
<script data-require="angular.js@*" data-semver="1.4.2" src="https://code.angularjs.org/1.4.2/angular.js"></script>
<script src="script.js"></script>
</head>

<body ng-app="jsonDateConverterExample">
<h2>Angular JSON Date Converter Filter Example</h2>
<div ng-controller="JsonDateController as dateCtrl">
<div>
Original JSON Date : {{sampleJsonDate}}
</div>
<h3>JavaScript dates in different formats :</h3>
<div>{{ sampleJsonDate | jsonDate }}</div>
<div>{{ sampleJsonDate | jsonDate : 'yyyy-MM-dd' }}</div>
<div>{{ sampleJsonDate | jsonDate :'medium' }}</div>
<div>{{ sampleJsonDate | jsonDate : 'yyyy-MM-dd HH:mm:ss Z' }}</div>
</div>
</body>

</html>
10 changes: 10 additions & 0 deletions JSONDateFilter/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var jsonDateConverterExample= angular.module('jsonDateConverterExample', [])
.controller('JsonDateController', ['$scope', function($scope) {
$scope.sampleJsonDate = '\/Date(1433913313004-0800)\/';
}]);

jsonDateConverterExample.filter('jsonDate', ['$filter', function ($filter) {
return function (input, format) {
return (input) ? $filter('date')(parseInt(input.substr(6)), format) : '';
};
}]);

0 comments on commit 2169260

Please sign in to comment.