Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  136] [ 5]  / answers: 1 / hits: 24172  / 5 Years ago, mon, april 29, 2019, 12:00:00

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);
}

More From » angular

 Answers
26

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);

[#52177] Monday, April 22, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kalia

Total Points: 92
Total Questions: 82
Total Answers: 120

Location: Laos
Member since Fri, Sep 11, 2020
4 Years ago
;