How can I get the date of a datepicker using angular 2?

1

I have a datepicker and I need to get the date to save it but I have no idea how to do it, if someone can, I attach the plugin code

    <div class="col-md-4">
                      <div class="form-group">
                        <label for="fecha"> {{'Fecha' | i18n}}</label>
                        <input type="text" #fecha="ngModel" (blur)="convocatoria.fecha=fecha.value" [(ngModel)]="convocatoria.fecha" name="fecha"
                          id="fecha" class="form-control datepicker" [saUiDatepicker]="{
                                dateFormat: 'dd/mm/yy'
                             }" required>
                      </div>
                    </div>
    
asked by Gonzalo Alberto 18.07.2017 в 17:10
source

2 answers

1

I think it would be something like this:

fecha() {
  let fechaActual = new Date();
  let dia = fechaActual.getDate().toString();
  let mes = (fechaActual.getMonth() + 1).toString();
  let anio = fechaActual.getFullYear().toString();
  let hora = fechaActual.getHours().toString();
  let minutos = fechaActual.getMinutes().toString();
  let segundos = fechaActual.getSeconds().toString();
  this.Fecha = anio + "-" + mes + "-" + dia;
  this.Hora = hora + ":" + minutos + ":" + segundos;
}
    
answered by 20.07.2017 в 03:26
0

Good morning. You should be able to access the value of your date from your ngModel

[(ngModel)]="convocatoria.fecha"

That is, if in the component.ts you access it using this.convocatoria.fecha

    
answered by 24.07.2017 в 18:03