我试图在模板视图中显示一些firebase时间戳,不幸的是,在angular 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
发布于 2018-10-24 19:21:23
您可以将时间戳转换为毫秒或日期:
<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>
发布于 2018-06-26 20:49:22
尝试这个{{ user.updatedAt.seconds * 1000 | date:'MM-dd-yyyy' }}
,时间戳有一个秒属性,所以您需要访问它,然后执行乘法和管道。希望这对你的案子有效。
发布于 2018-07-22 04:55:20
我在Angular中使用简单的自定义管道。它考虑了LOCALE_ID,你也可以使用所有的DatePipe格式:
import {formatDate} from '@angular/common';
import {Inject, LOCALE_ID, Pipe, PipeTransform} from '@angular/core';
import firebase from 'firebase/app';
import Timestamp = firebase.firestore.Timestamp;
@Pipe({
name: 'firestoreDate'
})
export class FirestoreDatePipe implements PipeTransform {
constructor(@Inject(LOCALE_ID) private locale: string) {
}
transform(timestamp: Timestamp, format?: string): string {
if (!timestamp?.toDate) {
return;
}
return formatDate(timestamp.toDate(), format || 'medium', this.locale);
}
}
测试角度为7- 10。
https://stackoverflow.com/questions/50770723
复制相似问题