AngularJS Datetime format filter in controller

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

READ :  Convert Serialize List Object to JSON String in C# ASP.NET

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]

{{user.DocDate | Datefjson}}

[/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]

AngularJS Datetime format in view and controller

http://angular.min.js

var app = angular.module(‘infinityknow’, [])
app.controller(‘dfilterCtrl’, function ($scope) {
$scope.todayDate = new Date();
});

dd/MM/yyyy format
{{todayDate | date:’dd/MM/yyyy’}}

READ :  Angular Date filtering and formatting JSON Data

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 steps By Steps

http://script.js

Angular JSON Date Converter Filter Example

Simple Original Data value JSON Date :

	  {{datajsonsamole}}
	  

AngularJS dates in different formats :

{{ datajsonsamole | Datefjson }}
{{ datajsonsamole | Datefjson : ‘yyyy-MM-dd’ }}
{{ datajsonsamole | Datefjson :’medium’ }}
{{ datajsonsamole | Datefjson : ‘yyyy-MM-dd HH:mm:ss Z’ }}
READ :  Nested ng-repeat Checkboxes in AngularJS Example

[/php]

Example

Leave a Comment