[英]Evaluating two epochs - Angular
我試過使用<
用另一個時代評估一個時代,但它總是返回 true 或 false,這是錯誤的。 我將它們都轉換為日期,但是發生了同樣的問題,根據我是否使用<
或>
判斷它是對還是錯,有些應該是真的,有些應該是假的。
auctionHasEnded(auctionEndDate: Date) {
let date: Date;
date = new Date();
return new Date(auctionEndDate) < date;
}
<td [ngStyle]="{'width': '55%'}" id="dateReceived" class="tableStyle" mat-cell *matCellDef="let row">
<span id="endDateTimeLabel" [ngStyle]="{'color':row.auctionEndDateTime > this.today ? 'red' : 'green' }">
{{auctionHasEnded(row.auctionEndDateTime)}}</span></td>
</ng-container>
auctionEndDateTime examples from JSON response: 1576779848, 1577379500, 1578069935, 1577999303
如果我有一個時代,我該如何評價它? 我認為將其轉換為日期並將其與新的 Date() 進行比較將是可行的方法,但它似乎沒有正確評估。 我很感激任何幫助。
為了檢查時間,您可以像這樣將今天的時間轉換為紀元:
this.today = +(new Date()/1000) // divide by 1000 to get seconds
1576779848 < this.today // true
JS 中的日期以毫秒為單位,如您所見: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.