ngx-bootstrap + angular 6 + datepicker

Asked

Viewed 218 times

2

Hello,

I am using ngx-bootstrap datepicker for the first time and am encountering some difficulties.

One of them is that when selecting the desired date, my input is in the exact format I need, as follows: '12/20/2018', but when I play on the console the input value, is presented as follows: 'Thu Dec 20 2018 23:26:21 GMT-0200 (Brasilia Daylight Saving Time)'.

How do I leave the input value with the Brazilian format: '20/12/2018'. I searched the documentation and could not find.

Evidence of how it’s working(wrong).

inserir a descrição da imagem aqui

Evidence of the properties:

inserir a descrição da imagem aqui

  • How you played on the console the input value?

  • As it is reactiveForms, I put it this way: console.log(this.formulario.Controls.data.value);

  • Dude, put console.log(this.formulario.controls.data) and check the properties if you have anything with 20/12/2018.

  • I looked too and I didn’t find, if you want, I can send the print with the evidence

  • I edited the question and inserted the photo

  • Know another datepicker that works well?

  • Dude, I don’t know much. Try it like this: var dia = this.formulario.controls.data.value;
console.log(dia.getDate()+"/"+Number(dia.getMonth()+1)+"/"+dia.getFullYear());


  • Boooa, so it was... Create an answer then I give ok

  • William, I am finding it difficult for the input to be in the correct format, if you can take a look at this question it would be of great help. https://answall.com/questions/401796/angular-8-ngx-bootstrap-datepicker

Show 4 more comments

1 answer

2


Build the date in the Brazilian format from the date you are returning from the element of Thu Dec 20 2018 23:26:21 GMT-0200 (Horário de Verão de Brasília):

var dia = this.formulario.controls.data.value;
dia = dia.getDate()+"/"+Number(dia.getMonth()+1)+"/"+dia.getFullYear();

The result will be : 20/12/2018

Browser other questions tagged

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