我使用datepicker
来自https://github.com/kekeh/mydatepicker/blob/master/README.md,我需要禁用日期,直到今天所以我需要获取当天的月份和年份并传递myDatePickerOptions我使用了新的日期( )函数得到我这样的日期(2017年4月6日星期五15:55:09 GMT + 0530(印度标准时间)所以不能使用它myDatepickerOptions
怎么能得到日月和年?我尝试过以下代码。
import { Component, OnInit,ViewEncapsulation } from '@angular/core';
import { HeaderComponent } from '../header/header.component';
import {IMyOptions, IMyDateModel,IMyDate} from 'mydatepicker';
import { TimepickerConfig } from 'ng2-bootstrap/timepicker';
import { FormGroup,FormControl,Validators } from '@angular/forms';
@Component({
selector: 'app-createsession',
templateUrl: './createsession.component.html',
styleUrls: ['./createsession.component.css'],
encapsulation: ViewEncapsulation.None
})
export class CreatesessionComponent implements OnInit {
eventform : FormGroup ;
public mytime: Date = new Date();
private myDatePickerOptions: IMyOptions = {
// need use the current day,month and year
disableUntil: {year: 2016, month: 8, day: 10},
dateFormat: 'dd.mm.yyyy'
};
constructor() { }
ngOnInit() {
console.log(this.mytime);
});
}
onDateChanged(event: IMyDateModel) {
// event properties are: event.date, event.jsdate, event.formatted and event.epoc
}
onSubmit(){
console.log(this.eventform.value);
}
}
答案 0 :(得分:1)
从当前日期中提取日期,年份和月份,并将其设置为disableUntil属性。
public mytime: Date = new Date();
currentYear: any = this.mytime.getUTCFullYear();
currentDate: any = this.mytime.getUTCDate();
currentMonth: any = this.mytime.getUTCMonth() + 1; //months from 1-12
private myDatePickerOptions: IMyOptions = {
// need use the current day,month and year
disableUntil: {year: this.currentYear, month: this.currentMonth, day: this.currentDate},
dateFormat: 'dd.mm.yyyy'
};