【发布时间】:2017-07-03 18:56:55
【问题描述】:
我有一个 Angular 应用程序,我在其中使用 firebase.database.ServerValue.TIMESTAMP 将记录存储到带有时间戳的 Firebase
现在我想检查添加到数据库的时间戳是否超过五分钟。
我尝试在我的组件中使用 moment ,但它只是不起作用。它正在提供虚假数据。我猜存储在 Firebase 中的数据是在我在印度的时代,所以如何让时刻在 Angular 中发挥作用。
我正在使用 Angular 2 Moment。
这是我试过的
import * as moment from 'moment/moment';
edit(i:number){
const val = moment.unix(this.comments[0].createdAt);// the value is a epoch time that is the standard that is stored in firebase
const present = moment().unix();
console.log(moment.duration(val.diff(present)));
}
this.cmets在date中使用时的值
let ts = new Date(this.comments[0].createdAt * 1000); = 8 月 5 日星期三 49474 20:09:20 GMT+0530(印度标准时间)
就目前而言——2017 年 7 月 4 日星期二 14:56:46 GMT+0530(印度标准时间)
请帮助解释为什么它的 cmets 数据没有在 7 月 3 日的时间下沉,因为它是当天在 firebase 上添加的
【问题讨论】:
-
this.comments[0].createdAt的值是多少? -
这是一个存储在firebase中的纪元时间
-
以毫秒(即 javascript 类型)或秒为单位?
-
秒 unix 时间戳
标签: javascript angular momentjs angular2-moment