最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to convert NgbDate to js Date object? - Stack Overflow

programmeradmin1浏览0评论

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

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);
    }
Share Improve this question edited Jul 22, 2020 at 13:51 Bar Gans asked Apr 29, 2019 at 12:07 Bar GansBar Gans 1,6632 gold badges13 silver badges25 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 43

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);
发布评论

评论列表(0)

  1. 暂无评论