如何将NgbDate转换为js Date对象?

16

我正在使用ng-bootstrap的ngbDate对象。我想将它转换为标准的Date对象。你该如何做到这一点?

以下是相关的.ts文件部分:

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);
    }
1个回答

42
根据 ngb-date.ts ,NgbDate 只是一个年、月和日的容器。

因此,你可以这样做:

const jsDate = new Date(ngbDate.year, ngbDate.month - 1, ngbDate.day);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接