我遇到TypeError:将日期绑定到Kendo Datatimepicker时,date.getTime不是一个函数。
core.js:15713 ERROR Error: Uncaught (in promise): TypeError: date.getTime is not a function
TypeError: date.getTime is not a function
at cloneDate (clone-date.js:13)
at DatePickerComponent.push../node_modules/@progress/kendo-angular-dateinputs/dist/es/datepicker/datepicker.component.js.DatePickerComponent.writeValue (datepicker.component.js:384)
web.api返回的日期采用以下格式
"2004-04-15T19:00:00"
我认为这是在抱怨,因为它不是有效的日期格式,因此尝试在下面进行转换,但是forEach出现错误不是一个函数。我已经评论了下面的代码。有人可以告诉我如何解决该问题。
我试图将字符串转换为日期
getFundDetails(selectedFundId: number) {
if (selectedFundId != null) {
this.fundService.getFundDetails(selectedFundId).subscribe((data: IFund[]) => {
// data.forEach((d) => {d.InceptionDate = new Date(d.InceptionDate); });
this.FundDetails = data;
this.SelectedFundId = this.FundDetails.FundId;
});
}
}
Viewmodel
public class FundViewModelNew
{
public int FundId { get; set; }
public string FundName { get; set; }
public bool? IsAnonymous { get; set; }
public string BloombergTicker { get; set; }
public int? InvestmentStatusId { get; set; }
public string InvestmentStatusName { get; set; }
public int? FlagShipFundId { get; set; }
public string FlagShipFundName { get; set; }
public DateTime? InceptionDate { get; set; }
public int? AccountMandateId { get; set; }
public string AccountMandateName { get; set; }
public int? VehicleTypeId { get; set; }
public string VehicleTypeName { get; set; }
}
接口
export interface IFund {
FundId: number;
FundName: string;
IsAnonymous: boolean;
BloombergTicker: string;
InvestmentStatusId: number;
InvestmentStatusName: string;
FlagShipFundId: number;
InceptionDate: Date;
AccountMandateId: number;
AccountMandateName: string;
VehicleTypeId: number;
VehicleTypeName: string;
}