[英]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.