16

I am using an ng-bootstrap ngbDate object. I would like to convert it to a standard Date object. How do you do this?

Here is the relevant part of the .ts file:

import {NgbCalendar, NgbDate} from "@ng-bootstrap/ng-bootstrap";
fromDate: NgbDate;
toDate: NgbDate;
constructor(calendar: NgbCalendar) {
    this.fromDate = calendar.getToday();
    this.toDate = calendar.getNext(calendar.getToday(), 'd', 10);
    }
Baruch Gans
  • 1,415
  • 1
  • 10
  • 21

1 Answers1

41

According to ngb-date.ts, NgbDate is just a container for year, month and day.

So, you could just do:

const jsDate = new Date(ngbDate.year, ngbDate.month - 1, ngbDate.day);
erikvimz
  • 5,256
  • 6
  • 44
  • 60