【问题标题】:push date + time timestamp firestore推送日期+时间时间戳firestore
【发布时间】:2019-10-06 09:58:25
【问题描述】:

我在我的反应形式和 Firestore 中使用 Angular Material 来存储日期和时间。由于 Angular Material 只有 Datepicker (https://material.angular.io/components/datepicker/overview) 而没有 Timepicker,所以我在另一个领域工作了时间,也就是说,我有两个领域。

但是当我想按日期和时间过滤数据时,这会给我带来其他问题。

我的问题是,如何将日期和时间放入并存储在单个 firestore 字段中?

目前这是我所拥有的:

components.ts

this.forma = fb.group ({
  fechaInicio: [ '', Validators.required ],
  horaInicio: [ '', Validators.required ],  
});

components.html

<div class="row">
  <mat-form-field class="col-lg-7 col-6" appearance="outline">
    <mat-label>Fecha inicio</mat-label>
    <input matInput [matDatepicker]="picker" placeholder="Fecha inicio" formControlName="fechaInicio">
    <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
    <mat-datepicker touchUi #picker></mat-datepicker>
  </mat-form-field>
  <mat-form-field class="col-lg-5 col-6" appearance="outline">
    <mat-label>Hora inicio</mat-label>
    <mat-select placeholder="Hora inicio" formControlName="horaInicio">
    <mat-option *ngFor="let hora of horas" [value]="hora">
      {{ hora }} hrs.
    </mat-option>
    </mat-select>
  </mat-form-field>
  </div>

Firestore 中的结果是这样的:

【问题讨论】:

    标签: angular google-cloud-firestore


    【解决方案1】:

    无论你想怎么称呼它都可以。然后你可以使用 orderByChild('created')。

    我在设置时间时也主要使用firebase.database.ServerValue.TIMESTAMP

    ref.child(key).set({
    id: itemId,
    content: itemContent,
    user: uid,
    created: firebase.database.ServerValue.TIMESTAMP 
    })
    

    【讨论】:

    • 我在其他地方看到过这个答案吗?你确定我在问什么?
    猜你喜欢
    • 2022-08-04
    • 1970-01-01
    • 2020-03-21
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 2014-05-22
    • 2018-11-05
    • 2019-05-10
    相关资源
    最近更新 更多