Get date formatted in HTML5

1

I have the following scenario. A form with two date fields

AndwhenIclickSearch,thedataisinthisformat

HowcanIgetthedateintheformat"yyyy-mm-dd" or "dd-mm-yyyy"? Without this additional data (Thu Oct, 00:00:00 GMT-0300), does anyone know?

Follow my HTML

form name="relatorioPorPeriodo" class="formRelatorio">
    <input class="form-control dataini" type="date" name="data_ini" ng-model="relatorio.dataini" required>
    <input class="form-control datafim" type="date" name="data_fim" ng-model="relatorio.datafim" required>
    <a class="btn btn-success" ng-disabled="relatorioPorPeriodo.$invalid" ng-click="pesquisaPorPeriodo(relatorio)">Pesquisar</a>
</form>

Controller

app.controller("RelatorioPorPeriodoCtrl", ['$scope', '$http', '$window', '$rootScope', '$routeParams', 'moment', function ($scope, $http, $window, $rootScope, $routeParams, moment) {

$scope.idempresa = $rootScope.idempresa = localStorage.getItem('idempresa');
$scope.empresa = $rootScope.empresa = localStorage.getItem('empresa');
$scope.usuario = $rootScope.usuario = localStorage.getItem('usuario');
$scope.idusuario = $rootScope.idusuario = localStorage.getItem('idusuario');

$scope.pesquisaPorPeriodo = function(relatorio){
    console.log(relatorio);
}
}]);
    
asked by anonymous 16.01.2018 / 20:10

1 answer

3

Using the library moment.js ( link );

var dataInicio = "Thu Oct 01 2015, 00:00:00 GMT-0300";
var dataInicioFormatada = moment(dataInicio).format('DD-MM-YYYY');

console.log(dataInicioFormatada);

Package npm for Angular: link

    
16.01.2018 / 20:40