首页 > 解决方案 > 如何使用角度日期管道转换 Firebase 时间戳

问题描述

我正在尝试在模板视图中显示一些 firebase 时间戳,不幸的是,角度 datePipe 没有运气。

<p>Seen {{user.updatedAt | date: 'yyyy/MM/dd h:mm:ss a'}}</p>

我确实收到此错误:

     ERROR Error: InvalidPipeArgument: 
'Unable to convert "Timestamp(seconds=1528515928, nanoseconds=105000000)" 
into a date' for pipe 'DatePipe

标签: angularfirebase

解决方案


您可以将时间戳转换为毫秒或日期:

<p>Seen {{user.updatedAt.toMillis() | date:'yyyy/MM/dd h:mm:ss a'}}</p>

或者

<p>Seen {{user.updatedAt.toDate() | date:'yyyy/MM/dd h:mm:ss a'}}</p>

推荐阅读