Angularjs filter change date format in controller

Angularjs filter change date format in controller

In this post we will give you information about Angularjs filter change date format in controller. Hear we will give you detail about Angularjs filter change date format in controllerAnd how to use it also give you demo for it if it is necessary.

In this post, i will show you how to change date format in angularjs controller. if you need to change date format in html then you can use date filter, but in controller you need to change date formate like yyyy-mm-dd to dd/MM/yyyy than how you can do it.

you can change date formate using $filter(‘date’)(date format timezone) in angular js controller.

Some days ago, someone ask me in comment. can you suggest me to change date formate in angular controller. he has date string and he wanted to change formate. so you don’t require to convert string, but you can do it directly by using $filter in your controller.

Just see this example and code.

Example:

Also see:AngularJS – scroll to a specific element using anchorscroll

<!doctype html>

<html>

<head>

<title>Angularjs filter change date format in controller - ItSolutionStuff.com</title>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

</head>

<body ng-app='myapp'>

<div ng-controller="myCtrl">

<p>2019-02-13</p>

<p><strong>{{ item }}</strong></p>

</div>

</body>

<script type="text/javascript">

var app = angular.module('myapp', []);

app.controller('myCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) {

$scope.item = $filter('date')('2019-02-13', "dd/MM/yyyy");

}]);

</script>

</html>

I hope it can help you…

Hope this code and post will helped you for implement Angularjs filter change date format in controller. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

6  +  3  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US