我们正在使用Angular 6,.NET mvc框架。根据日期选择,我需要将它传递给一个函数并填充一个下拉列表。但我没有以正确的格式检索日期。这是html:
onRequestPermissionsResult
这是ts文件。
<div class="form-group">
<label>Select Report Date:</label>
<kendo-datepicker [(value)]="value"
(valueChange)="onChange($event)">
</kendo-datepicker>
</div>
Console.log上的值是
public lobs: Array<VTO> = [];
public value: Date = new Date();
public onChange(value: Date): void {
console.log('change', value);
this._vtos.getLOBs(value)
.subscribe(data => this.lobs = data,
error => this.errorMsg = error);
}
虽然我需要'MM / dd / yyyy'格式,所以我得到05/10/2018。请指教。
答案 0 :(得分:1)
尝试:
public onChange(value: Date): void {
console.log('change', this.getFormattedDate(value));
this._vtos.getLOBs(value)
.subscribe(data => this.lobs = data,
error => this.errorMsg = error);
}
getFormattedDate(date) {
let year = date.getFullYear();
let month = (1 + date.getMonth()).toString();
month = month.length > 1 ? month : '0' + month;
let day = date.getDate().toString();
day = day.length > 1 ? day : '0' + day;
return month + '/' + day + '/' + year;
}
答案 1 :(得分:1)
//use format input like below
<kendo-datepicker
[format]="'MM/dd/yyyy'"
[value]="value"
></kendo-datepicker>