Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 离子型Firebase云函数时间戳_Angular_Ionic Framework_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

Angular 离子型Firebase云函数时间戳

Angular 离子型Firebase云函数时间戳,angular,ionic-framework,google-cloud-firestore,google-cloud-functions,Angular,Ionic Framework,Google Cloud Firestore,Google Cloud Functions,谢谢你的帮助。(更新问题以便澄清) 1.-在ioinic(angular)HTML中,我请求输入:“开始”。 html表单类型是timestamp,因此在html中我能够“以图形方式”选择日期 表格如下: <ion-label>Start</ion-label> <ion-datetime formControlName="start" type="timestamp" displayFormat="D

谢谢你的帮助。(更新问题以便澄清)

1.-在ioinic(angular)HTML中,我请求输入:“开始”。 html表单类型是timestamp,因此在html中我能够“以图形方式”选择日期

表格如下:

<ion-label>Start</ion-label>
  <ion-datetime formControlName="start" type="timestamp" 
    displayFormat="DMMMYYYY" min="2019" max="2070"></ion-datetime>
</ion-item>
在Firestore中保存为时间戳:7月15日01:23:00 utc 5

为了记录在案,如果我保存为

{start: start}
它在Firestore中保存为:2020-07-15T01:23:00-05:00

,但我仍然无法用html显示…答案可能在这里吗

3.-然后,如果我获得数据并通过html订阅: 示例:(使用第一个显示的格式)

在html中显示我想要的日期…2020年7月15日

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云函数中进行转换


感谢您的帮助。

爱奥尼亚使用ISO时间,因此,当您以所需格式在firebase中保存数据时,因此当您在表单中重新填充数据时,日期是以您的格式设置的,而不是ISO格式,因此您需要像declare一样在ts文件中设置值

startDate:Date; 
然后在数据到达时使用

this.startDate = newDate(here put the value from firebase).toISOString(); 
同样的事情到了结束日期,因此应该是可行的,或者你可以使用管道和地图来实现这一点

更新部分

您可以在数据库yyyy-MM-ddT00:00:00.000z中以iso格式保存时间,以便从firebase获取数据时 正如我在你扇扇子之前告诉你的,或者使用管道和贴图来解决它,或者通过以下方式:

const splitedDate = firebaseDate.split('T');
const ymd = splitedDate[0];
// now ymd is yyyy-MM-dd
const time = splitedDate[1].split('.');
// now time is 00:00:00
const customDate = this.formatToDate(ymd.split('-'), time);

formatToDate(dtime, time) {
    const date = new Date(dtime[0], (parseInt(dtime[1]) - 1), dtime[2]); 
    const month = date.toLocaleString('default', { month: 'short' }); 
    return `${dtime[2]} of ${month} at ${time}`;
}

Ionic使用ISO时间,因此当您以想要的格式在firebase中保存数据时,因此当您在表单中重新填充数据时,日期是以您的格式设置的,而不是ISO格式,因此您需要像declare一样在ts文件中设置值

startDate:Date; 
然后在数据到达时使用

this.startDate = newDate(here put the value from firebase).toISOString(); 
同样的事情到了结束日期,因此应该是可行的,或者你可以使用管道和地图来实现这一点

更新部分

您可以在数据库yyyy-MM-ddT00:00:00.000z中以iso格式保存时间,以便从firebase获取数据时 正如我在你扇扇子之前告诉你的,或者使用管道和贴图来解决它,或者通过以下方式:

const splitedDate = firebaseDate.split('T');
const ymd = splitedDate[0];
// now ymd is yyyy-MM-dd
const time = splitedDate[1].split('.');
// now time is 00:00:00
const customDate = this.formatToDate(ymd.split('-'), time);

formatToDate(dtime, time) {
    const date = new Date(dtime[0], (parseInt(dtime[1]) - 1), dtime[2]); 
    const month = date.toLocaleString('default', { month: 'short' }); 
    return `${dtime[2]} of ${month} at ${time}`;
}

最后使用
解决了这个问题
const start=新日期(data.start.seconds*1000);不知道为什么console.log()显示了不同的格式,但在将其存储到firestore中时,它按照我的需要保存了它,就像通过ionic存储在其他firestore文档中一样。感谢那些帮忙的人的时间和帮助!:)

最后使用
解决了这个问题
const start=新日期(data.start.seconds*1000);不知道为什么console.log()显示了不同的格式,但在将其存储到firestore中时,它按照我的需要保存了它,就像通过ionic存储在其他firestore文档中一样。感谢那些帮忙的人的时间和帮助!:)

虽然您需要添加一些代码,因为仅列出您所拥有的不会让任何人知道您的问题可能在哪里,但ionic使用ISO时间,因此当您以所需格式在firebase中保存数据时,因此当您在表单中重新填充数据时,日期以您的格式设置,而不是iso格式,因此您需要在ts文件中设置值,如declare startDate:Date;然后在数据到达时使用this.startDate=newDate(这里输入来自firebase.toISOString()的值);同样的事情到结束日期,因此应该工作,或者你可以使用管道和地图来实现这一点。谢谢你@MostafaHarb,这是有用的,我理解代码的需要,并将尝试尽快发布,仍然感谢您的想法。感谢@MostafaHarb仍然没有解决问题到底是什么问题?虽然您需要添加一些代码,因为仅仅列出您的代码不会让任何人知道您的问题可能在哪里,但ionic使用ISO时间,因此当您以所需格式在firebase中保存数据时,因此,当您在表单中重新填充数据时,日期是以您的格式设置的,而不是iso格式,因此您需要在ts文件中设置值,如declare startDate:Date;然后在数据到达时使用this.startDate=newDate(这里输入来自firebase.toISOString()的值);同样的事情到了结束日期,因此应该可以工作,或者你可以使用管道和地图来实现这一点。谢谢你@MostafaHarb,这是有用的,我理解代码的需要,并会尽快发布,仍然感谢你的想法。谢谢@MostafaHarb仍然没有解决它到底还有什么问题?伙计,正如我所理解的,现在我在utc 5的01:23:00保存7月15日,但你的建议是保存:2020-07-15T01:23:00-05:00,我知道这可能会起作用,但这带来了一个不同的问题,与HTML有关,它现在的存储方式,我使用let d of(data | async)…{d.start.toDate date()| date:“dd/MMM/yy”}在HTML中显示我想要的日期…2020年7月15日,对于2020-07-15T01:23:00-05:00,虽然它可以用于云功能,但我无法到达那里,因为我被困在HTML的显示中,那会是什么情况?谢谢你advance@Chucho7你误解了我的意思,senario是你以你想要的格式在fb中保存数据,当从db中取回数据时,得到像(new Date(res.Date).toISOString()这样的值,因此日期将更改为picker时区,因为时区不采用utc的值,它需要iso格式的时间,因此,当再次将数据输入数据库时,需要将其值重新转换为utc中所需的格式。所以为了更快的工作,你可以