我目前正在制作一个应用程序,您可以在其中查看您最近的通话。我希望能够显示它是多久以前的。如果它长于一周前,它将显示日期(例如 2020-06-19)。如果它少于一周前,则需要显示日期(星期三),而当它是今天时,它只显示时间( 11:03)。
任何人都知道如何做到这一点?到目前为止,这是我的代码
HTML
<div *ngFor="let blocked of sortData; let i=index" class="recent-holder">
<ion-icon name="ios-close-circle-outline" class="icon" (click)="removeBlocked(i)"></ion-icon>
<div class="recent-number" (click)="blockedModal()">
<img class="image" alt="recent user image" src="../../assets/images/numbers/{{blocked.number}}.png" onerror="if (this.src !== '../../assets/images/numbers/unknown.png') this.src = '../../assets/images/numbers/unknown.png';">
<h2>{{blocked.name}}</h2>
<div class="date-ending">
<h3>{{blocked.blocktimeend}}</h3>
<h3>{{blocked.blockdateend | date: 'd-MM-y'}}</h3>
</div>
</div>
</div>
打字稿
export class BlockednumbersPage implements OnInit {
blocked = (data).blocked;
get sortData() {
return this.blocked.sort((a, b) => {
return (new Date(b.blockdateend) as any) - (new Date(a.blockdateend) as any);
});
}
}
如果需要任何其他信息,请告诉我。谢谢