Angularjs Format date

0

How to format the date in the controller of input type="DATE"?

I have this return in the controller ...

Sat Aug 06 2016 00:00:00 GMT-0300 (Hora oficial do Brasil)

Mon Aug 01 2016 00:00:00 GMT-0300 (Hora oficial do Brasil)

You can format for

01-08-2016?
    
asked by anonymous 16.08.2016 / 00:54

3 answers

5

You can use the angle date filter .

Editing to change the Date format on the Controller

Example:

var app = angular.module('myApp', []);
app.controller('datCtrl', function($scope, $filter) {
    $scope.today = new Date();
    $scope.todayString = $filter('date')(new Date(), 'dd-MM-yyyy');
  
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divng-app="myApp" ng-controller="datCtrl">

<p>Data = {{ today | date:'dd-MM-yyyy' }}</p>
  
<p>Data direto do Controller = {{ todayString }}</p>

</div>
    
16.08.2016 / 01:10
1

Hello friend, have a great javascript library for date formatting link

Your controller would look like this moment (suData) .format ('DD-MM-YYYY');

Library document link

    
13.09.2016 / 14:49
0

If it's inside the Angular controller, then you should create a formatter using just JavaScript.

Here is the list of references for date functions for JavaScript .

function pad(n) {
    return n < 10 ? '0' + n : n;
}

function formataMinhaData (data) {
    return pad(data.getDate()) + '/' + pad(data.getMonth() + 1) + '/' + data.getFullYear();
}
    
16.08.2016 / 09:55