ionic 4:尝试显示“时间戳记”字段的一部分,但出现错误

时间:2019-03-18 06:50:39

标签: firebase timestamp ionic4

我试图在我的ionic 4 html页面上显示时间戳,但出现错误-这是html中的代码

<ion-title> {{currentDetails?.date.seconds | date: 'dd-MM-yyy'}} </ion-title>

这是我遇到的错误

DetailsPage.html:5 ERROR TypeError: Cannot read property 'seconds' of undefined
    at Object.eval [as updateRenderer] (DetailsPage.html:5)
    at Object.debugUpdateRenderer [as updateRenderer] (core.js:22503)
    at checkAndUpdateView (core.js:21878)
    at callViewAction (co....

我已经使用类似的代码在代码的其他区域显示日期,并且似乎没有错误。

1 个答案:

答案 0 :(得分:0)

那里没有足够的细节,但是我假设currentDetails?.date是一个JavaScript日期对象。如果是,那么可以使用扩展方法getTime()来获取时间戳(以毫秒为单位)

{{currentDetails?.date.getTime() | date: 'dd-MM-yyy'}}