Angular Bootstrap Datepicker 给我们日期对象。我想要它作为日期
Angular Bootstrap Datepicker Gives us date object . I want it as Date
我希望我的约会对象是 "Wed Aug 07 2019 16:42:07 GMT+0530 (India Standard Time)"
但我得到 { year: 1789, month: 7, day: 14 } 来自 ngbDatepicker
任何帮助将不胜感激
您必须将对象转换为日期...您可以在 select
方法中执行以下操作:
相关TS:
import {Component} from '@angular/core';
@Component({
selector: 'ngbd-datepicker-popup',
templateUrl: './datepicker-popup.html'
})
export class NgbdDatepickerPopup {
model;
convertedDate;
select(d){
console.log(d);
this.convertedDate = new Date(d.year, d.month, d.day);
}
}
相关HTML:
<div class="input-group ">
<input id="datepicker" class="form-control col-7" [(ngModel)]="model" placeholder="" ngbDatepicker #date="ngbDatepicker" required (ngModelChange)="select(model)" pattern="[0-9]{4}[-][0-9]{2}[-][0-9]{2}">
<div class="input-group-append">
<button class="btn btn-outline-secondary picto-calender" (click)="date.toggle()" type="button"></button>
</div>
</div>
selected Date: {{convertedDate}}
我希望我的约会对象是 "Wed Aug 07 2019 16:42:07 GMT+0530 (India Standard Time)" 但我得到 { year: 1789, month: 7, day: 14 } 来自 ngbDatepicker 任何帮助将不胜感激
您必须将对象转换为日期...您可以在 select
方法中执行以下操作:
相关TS:
import {Component} from '@angular/core';
@Component({
selector: 'ngbd-datepicker-popup',
templateUrl: './datepicker-popup.html'
})
export class NgbdDatepickerPopup {
model;
convertedDate;
select(d){
console.log(d);
this.convertedDate = new Date(d.year, d.month, d.day);
}
}
相关HTML:
<div class="input-group ">
<input id="datepicker" class="form-control col-7" [(ngModel)]="model" placeholder="" ngbDatepicker #date="ngbDatepicker" required (ngModelChange)="select(model)" pattern="[0-9]{4}[-][0-9]{2}[-][0-9]{2}">
<div class="input-group-append">
<button class="btn btn-outline-secondary picto-calender" (click)="date.toggle()" type="button"></button>
</div>
</div>
selected Date: {{convertedDate}}