我正在使用datepicker
从这里 https://github.com/kekeh/mydatepicker/blob/master/README.md 我需要禁用日期直到今天,所以我需要获取当前日期的月份和年份并传递它 myDatePicker选项 我使用新的 Date(( 函数来获取我得到这样的日期(星期四 Apr 06 2017 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);
}
}
从当前日期中提取日期、年份和月份,并将其设置为 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'
};