代码之家  ›  专栏  ›  技术社区  ›  Paco Zevallos

推送日期+时间戳firestore

  •  0
  • Paco Zevallos  · 技术社区  · 5 年前

    我用角材料在我的反应形式和Firestore存储的日期和时间。因为Angular材质只有Datepicker( https://material.angular.io/components/datepicker/overview )我在另一个领域工作过,也就是说,我有两个领域。

    但当我想按日期和时间过滤数据时,这会导致其他问题。

    我的问题是,

    组件.ts

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

    组件.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的结果如下: enter image description here enter image description here

    1 回复  |  直到 5 年前
        1
  •  0
  •   Shubham    5 年前

    不管你叫什么都可以。然后可以使用orderByChild('created')。

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