Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-bootstrap how get string or Date format no object

I use ng-bootstrap Datepicker something like here: plnkr example

but now after choose date I get object

Model: {
  "year": 2016,
  "month": 10,
  "day": 13
}

But I would like get date in this format 2016-10-17

like image 548
Marko Avatar asked Oct 17 '16 09:10

Marko


2 Answers

You can use NgbDateParserFormatter

import {NgbDateParserFormatter} from '@ng-bootstrap/ng-bootstrap';

constructor(private parserFormatter: NgbDateParserFormatter) {}
...
let date = this.parserFormatter.format(this.model);

Plunker

like image 54
yurzui Avatar answered Oct 04 '22 21:10

yurzui


You can extract the particular properties of the object and construct your date string like this:

let date = this.Model.year + '-' + this.Model.month + '-' + this.Model.day
like image 29
Alexander Ciesielski Avatar answered Oct 04 '22 23:10

Alexander Ciesielski