Get HTML5 formatted date

Asked

Viewed 53 times

1

I have the following scenario. A form with two date fields inserir a descrição da imagem aqui

And when I click search, the data is in this format inserir a descrição da imagem aqui

How can I get the date in the "yyyy-mm-dd" or "dd-mm-yyyy" format? Without this additional data (Thu Oct, 00:00:00 GMT-0300), someone knows?

Follows 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);
}
}]);
  • I advise using the library Moment,js (https://momentjs.com/) to handle date formats, time interval counts, etc. Use the function Moment(). format(").

  • Yes, I do, but I don’t know how to use it, because in the given example I have to put the date in hand.

  • How do I install it to use with angular? Can’t install with npm? Or download?

  • Package npm for Angular: https://www.npmjs.com/package/angular-moment

1 answer

3


  • I’ve already imported Moment.js into index.html ?

  • Yes, I put this: ngular.module('fooApp') . controller('Fooctrl', ['$Scope', 'Moment', Function ($Scope, Moment) .

  • I posted my controller in the description.

  • I installed via CDNJS and it didn’t help. You can show me how my controller looks?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.