【发布时间】:2020-09-16 00:01:21
【问题描述】:
我有 div 元素,我想在它的创建时间超过 6 个月前隐藏它。如何在 typescript 和 angular 7 中实现这一点
AngularJS - hide/show div if date is within last 6 months
我曾这样尝试过,它会引发错误“DateConstructor”类型上不存在属性“getMonth” HTML:
<div class="request" *ngIf="request.createTime>six_month_before_date">
<!-Only then display data-->
</div>
打字稿
public date = new Date() ;
public six_month_before_date= this.date.setMonth(this.date.getMonth() -6);
private getRequestDuration(request) {
let createdDate = new Date(request.createTime);
let timeInMilliSeconds = this.currentDate.getTime() -
createdDate.getTime();
let seconds = timeInMilliSeconds / 1000;
let minutes = seconds / 60;
let hours = minutes / 60 + 5; // FIXME: EST Offset
hours = hours > 0 ? hours : 0; // FIXME: Hack to address time-stamp conversions / daylight savings time
let days = hours / 24;
return (days > 0 ? Math.floor(days) + ' days, ' : '') + Math.floor(hours % 24) + ' hours';
}
【问题讨论】:
标签: javascript html angular typescript