angular - TypeError:date.getTime 在角度使用时不是函数
问题描述
我正在我的 Angular 7 应用程序中实现 kendo datetimepicker 控件并收到错误 TypeError: date.getTime is not a function
我绑定到 datetimepicker 之前的日期是 /Date(779929200000)/
我写了一个方法来把它转换成日期。所以我可以看到日期选择器,但可以在浏览器的控制台窗口上看到这个错误
用户界面
<label for="inputFax" class="col-md-2 col-form-label header">Inception Date</label>
<div class="col-md-3">
<div *ngIf="!EditMode">{{getInceptionDate}}</div>
<kendo-datepicker *ngIf="EditMode" [format]="'dd MMM, yyyy'" [(ngModel)]="getInceptionDate" > </kendo-datepicker>
</div>
零件
get getInceptionDate(): string {
if (this.FundDetails.Entity.INCEPTION_DATE != null) {
const dateString = this.FundDetails.Entity.INCEPTION_DATE;
const results = parseInt(dateString.replace(/\/Date\(([0-9]+)[^+]\//i, "$1"));
const date = new Date(results);
const month = date.toLocaleString('en-us', { month: 'long' });
return (month + '-' + date.getFullYear());
}
}
解决方案
我认为您应该将您的重命名getInceptionDate
为类似formatInceptionDate
并创建另一个 getInceptionDate ,如下所示:
get getInceptionDate(): Date {
if (this.FundDetails.Entity.INCEPTION_DATE != null) {
return new Date(this.FundDetails.Entity.INCEPTION_DATE);
}
}
推荐阅读
- python - 数组中字符串之间的常用字符
- android - 有没有一种简单的方法可以从 Kotlin 的字符串资源文件中获取具有默认值的数据类对象?
- sql - 当我们在语句中使用联接时,在选择语句中使用案例表达式时出错
- python - numpy.random.randint 比 random.randint 慢
- javascript - Javascript regex - 重用模式来捕获组
- email - 在 yii2 中用作邮件附件的 PDF 生成器的更好解决方案
- python - CNN 时如何检查图像大小?
- sql - 编写 SQL 查询以查找链接到相同用户 ID 的不同用户
- mysql - 不同的SQL写法造成不同的时间成本
- java - 使用 SimpleDateFormatter 获得不一致的结果