AngularJS Datetime format filter in controller
Welcome to the In infinityknow.com website! You will Step By Step learn web programming, easy and very fun. This website allmost provides you with a complete web programming tutorial presented in an easy-to-follow manner. Each web programming tutorial has all the practical examples with web programming script and screenshots available.For AngularJS Datetime format filter in controller
Syntax of Date Filter in AngularJS
[php]
{{yourdateexpression | date : format}}
[/php]
Convert JSON date to JavaScript date in angularjs
Return json
[php]
//input – “DocDate”:”\/Date(1127318400000-0000)\/”
[/php]
HTML part
[php]
[/php]
script.js
[php]
app.filter(‘Datefjson’, [‘$filter’, function ($filter) {
return function (input, format) {
return (input)
? $filter(‘date’)(parseInt(input.substr(6)), format)
: ”;
};
}]);
[/php]
[php]
app.filter(“dateFilter”, function ($filter) {
return function (item) {
if (item != null) {
var dateparse = new Date(parseInt(item.substr(6)));
//return like format ‘yyyy-MM-dd’
return $filter(‘date’)(dateparse, ‘yyyy-MM-dd’);
}
return “”;
};
});
[/php]
AngularJS Datetime format in view and controller
[php]
var app = angular.module(‘infinityknow’, [])
app.controller(‘dfilterCtrl’, function ($scope) {
$scope.todayDate = new Date();
});
{{todayDate | date:’dd/MM/yyyy’}}
dd, MMMM yyyy format
{{todayDate | date:’dd, MMMM yyyy’}}
24 Hour time
{{todayDate | date:’HH:mm:ss’}}
12 Hour time
{{todayDate | date:’hh:mm:ss a’}}
[/php]
Convert JSON date to JavaScript date in angular
[php]
syntax
——-
angular.module(‘Dateinfinityknow’, [])
.controller(‘DatefjsonController’, [‘$scope’, function($scope) {
$scope.datajsonsamole = ‘\/Date(1433913313004-0800)\/’;
}]);
Example
——-
angular.module(‘Dateinfinityknow’, [])
.filter(‘Datefjson’, [‘$filter’, function ($filter) {
return function (input, format) {
return (input)
? $filter(‘date’)(parseInt(input.substr(6)), format)
: ”;
};
}]);
[/php]
Angular JSON Date Converter Filter Example steps By Steps
[php]
Angular JSON Date Converter Filter Example
{{datajsonsamole}}
AngularJS dates in different formats :
[/php]