【发布时间】:2020-11-04 15:07:55
【问题描述】:
感谢您的帮助。 (更新问题以进行澄清)
1.- 在 ioinic(角度)HTML 中,我要求输入:“开始”。 html 表单类型是时间戳,所以在 html 中我可以“以图形方式”选择一个日期。
表格是这样的:
<ion-label>Start</ion-label>
<ion-datetime formControlName="start" type="timestamp"
displayFormat="DMMMYYYY" min="2019" max="2070"></ion-datetime>
</ion-item>
2.- 然后我将其作为新日期(输入值)存储在 firestore 中
example--- {start: new Date(start)}
在 Firestore 中保存为时间戳:7 月 15 日 01:23:00 UTC 5
作为记录,如果我保存为
{start: start}
它在 Firestore 中保存为:2020-07-15T01:23:00-05:00
,但是我仍然无法在 html 中显示回来……答案可以在这里吗?
3.- 然后,如果我获取数据并通过 html 订阅: 示例:(使用第一个显示的格式)
let d of (data| async).....{{d.start.toDate()|date: "dd/MMM/yy"}}
在 html 中显示我想要的日期...15/jul/2020
4.- 如果我只是将相同的 d.start 传递给另一个函数并直接保存到 Firestore,它仍然会像保存在另一个文档中一样保存。
5.- 问题是我将此数据作为数据的一部分传递给可调用的云函数,然后,已经在我检索的 CF 函数中:
const start = data.start;
6.- 这是问题所在,无论我如何尝试,它都不会像在其他 firestore 文档中那样存储到另一个 firebase 文档。
试过了:
const start = new Date(data.start)
const start = new Date(data.start.nanoseconds)
const start = new Date(data.starts seconds)
const start = data.start
const start = data.start.nanoseconds.
etc... many combinations truly, read, searched, googled and can't get it.
有时它存储 NaN,有时只是几秒/纳秒,有时返回 500 无效日期格式,有时按我的意愿存储,但使用 1970 年的日期(这是最接近的日期)
我正在尝试仅在 Firestore Cloud Function 中进行转换。
感谢您的帮助。
【问题讨论】:
-
虽然你需要添加一些代码,因为仅仅列出你所拥有的不会让任何人知道你的问题可能出在哪里,但是 ionic 使用 ISO 时间,所以当你以你想要的格式保存数据到 firebase 时,因此当您在表单中重新填写数据时,日期会以您的格式而不是 iso 格式设置,因此您需要在 ts 文件中设置 vales,如声明 startDate:Date;然后在数据到达时使用 this.startDate = newDate(here put the value from firebase).toISOString();和结束日期一样,因此应该可以工作,或者您可以使用管道和地图来实现这一点。
-
感谢 U @MostafaHarb,这很有用,我了解代码的需要,并会尽快发布,仍然感谢您的想法。
-
谢谢@MostafaHarb 还没解决
-
究竟还有什么问题?
标签: angular ionic-framework google-cloud-firestore google-cloud-functions