【发布时间】:2020-09-14 15:39:09
【问题描述】:
在 Angular 7 中,我想根据创建的时间隐藏一个 div,如果它是过去 6 个月,那么我想隐藏一个 div 如何在创建的时间超过 6 个月时修改 html 以隐藏 div
HTML。
<div class="request" *ngIf="request.status != 'CANCELLED' && request.duration">
打字稿 /** 加载任务的持续时间 */
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 q> 0 ? Math.floor(days) + ' days, ' : '') + Math.floor(hours % 24) + ' hours';
}
requests.duration = this.getRequestDuration(requests);
Request Object
Object
agingCurrent: 121777671
agingTotal: 121902671
createTime: "2020-09-14T06:49:20"
createdBySso: "503184132"
duration: "1 days, 20 hours"
indErrored: false
indSavedToMdm: "TRUE"
indSubscribed: "TRUE"
partyId: "160598"
requestId: 627723
requestType: "Internal subscribe"
riskCategory: "ONE"
riskLevel: "MODERATE"
state: {status: "Active", label: "-"}
status: "APPROVED"
statusUpdateTime: "2020-09-14T06:51:25"
supplierId: "S18961"
supplierName: "LM Wind Power (Spain) SA"
transactionId: null
type: "SUBSCRIBE_INTERNAL"
updateTime: "2020-09-14T06:51:25"
version: 15
【问题讨论】:
-
你为什么不用moment.js。它非常适合这种事情。这是一篇关于如何使用它的 SO 帖子。stackoverflow.com/questions/33440646/…
-
嗨 Darren 属性 'getMonth' 在类型 'DateConstructor'.ts(2339) 上不存在
-
如何解决这个错误
标签: javascript html angular typescript