You can make a filter that receives the date and format as you wish:
angular.module("app", []);
angular.module('app').controller("myctrl", function() {
var ctrl = this;
ctrl.names = [{tempoEspera: "2015-01-01T01:00:00"}, {tempoEspera: "2016-01-01T23:00:59"}]
});
// cria um filtro que receba uma data e formata-a atraves do momentjs
angular.module('app').filter('formatarData', function() {
return function(input) {
if (!input) {
return '';
}
return moment(input).format("LLLL"); // formata conforme a localização do utilizador. Alterar esta linha para alterar a forma como a data e formatada.
}
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
<div ng-app="app" ng-controller="myctrl as ctrl">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Test</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in ctrl.names">
<!--A cada iteração do ng-repeat, o filtro formatarData e aplicado ao conteudo da variavel x.TempoEspera -->
<td>{{x.tempoEspera | formatarData}}</td>
</tr>
</tbody>
</table>
</div>
In the example above, a filter called formatarData
which receives a string representing a date and formats it using the momentjs
.
In this specific case, format the date in the format LLLL
- Month name, day of Month, day of week, year, time.
However, you can change the filter code to format the date to whatever format you need.
leozado you want to format your date in a specific format?
– Pedro Camara Junior
yes, I would like it not to return this date 'RAW' but in this following format for example. 1 minutes ago or 10 hours ago.
– leozado
You want to show the elapsed time of the informed date so far?
– Pedro Camara Junior