【问题标题】:Reduce data fetched/displayed from timestamp减少从时间戳获取/显示的数据
【发布时间】:2019-06-30 11:19:15
【问题描述】:

我正在尝试存储和获取用户请求的日期。

我正在创建这样的时间戳:

const date = firebase.firestore.FieldValue.serverTimestamp();

我获取/显示数据的方式:

<tr class="tr-content" *ngFor="let request of requests" routerLink="/admin/requests/{{ request.id }}">
  <th scope="row" class="text-center"> {{ request.id }} </th>
  <td>{{ request.name }}</td>
  <td>{{ request.company }}</td>
  <td>{{ request.type }}</td>
  <td>{{ request.budget }}</td>
  <td>{{ request.date.toDate() }}</td>
  <td class="text-center"> > </td>
</tr>

有效,但数据显示如下:

2019 年 6 月 30 日星期日 14:03:37 GMT+0300(Osteuropäische Sommerzeit)

如何减少显示的信息? F.e.只有日期和时间。

【问题讨论】:

    标签: angular typescript firebase google-cloud-firestore


    【解决方案1】:

    您可以使用日期管道https://angular.io/api/common/DatePipe 并将模式格式传递给它,您可以执行以下操作:&lt;td&gt;{{ request.date.toDate() | date:'dd/MM/yy'}}&lt;/td&gt;

    或者,您可以为此使用 Moment.JS,它也适用于 angular。见https://github.com/urish/angular-moment。 `

    【讨论】:

    • 很高兴为您提供帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 2021-05-19
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多