管道日期角度“无法转换"时间戳"

编程入门 行业动态 更新时间:2024-10-26 16:25:24
本文介绍了管道日期角度“无法转换"时间戳"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用有角度的管道,特别是以下内容:{{fechaCreacion | date: 'medium'}},并且出现以下错误:Unable to convert Timestamp (seconds = 1528157765, nanoseconds = 878000000)" into a date 'for pipe' DatePipe'

I'm trying to use a pipe in angular, specifically the following: {{fechaCreacion | date: 'medium'}} and I get the following error: Unable to convert Timestamp (seconds = 1528157765, nanoseconds = 878000000)" into a date 'for pipe' DatePipe'

这是我在Firestore中的注册:

This is my registration in Firestore:

当我刚刚离开{{ fechaCreacion }}时,它向我显示以下内容:

When I just leave {{ fechaCreacion }} it shows me the following:

我该如何解决?

我正在使用:

角度6

"angularfire2":"^ 5.0.0-rc.10"

"angularfire2": "^5.0.0-rc.10"

"firebase":"^ 5.0.4",

"firebase": "^5.0.4",

component.ts

component.ts

aviso: any = {}; id; titulo; descripcion; fechaCreacion; categoria; constructor( private fs: FirebaseService, private activatedRoute: ActivatedRoute) { } ngOnInit() { this.id = this.activatedRoute.snapshot.params['id']; this.fs.getAvisoObject(this.id).valueChanges().forEach(aviso => { this.titulo= aviso.titulo, this.descripcion = aviso.descripcion, this.fechaCreacion = aviso.fechaCreacion, this.categoria = aviso.categoria }); }

component.html

component.html

<mat-card class="px-3 px-md-5 py-3 py-md-4 rounded"> <div class="row no-gutters small pb-2 mb-3 d-flex justify-content-between border-bottom text-muted"> <div> <span>{{ categoria }}</span> </div> <div> <span>{{ fechaCreacion | date : 'medium' }}</span> </div> </div> <h2 class="font-weight-bold">{{ titulo }}</h2> <h5 class="font-weight-light">{{ descripcion }}</h5> </mat-card>

service.ts

service.ts

getAvisoObject(id: string) { this.avisoObject = this.afs.doc('avisos/' + id); return this.avisoObject; }

推荐答案

在Firestore中处理时间戳记类型数据(即显示的文档中的fechaCreacion字段)时,Firestore客户端库将为您提供时间戳类型对象,以响应查询.您需要使用此时间戳来设置日期格式,以便在浏览器中显示.

When dealing with timestamp type data in Firestore (that's your fechaCreacion field in the document shown), the Firestore client libraries will give you a Timestamp type object in response to queries. You need to use this Timestamp to format a date for display in the browser.

时间戳表示具有纳秒精度的时间,其中涉及两个整数,您将在屏幕上看到它们.如果要使用JavaScript Date对象,则可以使用 toDate( )在该时间戳上进行转换,或将其转换为屏幕上的内容.

Timestamp represents times with nanosecond precision, which involves two integers, which you are seeing on screen. If you want a JavaScript Date object instead, you could use the toDate() method on that Timestamp to convert it, or whatever it is you need to render that on screen.

更多推荐

管道日期角度“无法转换"时间戳"

本文发布于:2023-11-23 14:51:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管道   角度   日期   时间   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!