我有一个角度应用程序,我使用 firebase.database.ServerValue.TIMESTAMP
将记录存储到firebase中的时间戳
现在我想检查添加到数据库的时间戳是否超过五分钟 .
我尝试在我的组件中使用时刻,但它只是起作用 . 它提供了错误的数据 . 我想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.com的 Value
let ts = new Date(this.comments[0].createdAt * 1000);
= Wed Aug 05 49474 20:09:20 GMT 0530(印度标准时间)
现在它的喜欢 - Tue Jul 04 2017 14:56:46 GMT 0530(印度标准时间)
请帮助为什么评论数据不会随着7月3日的时间而下沉,因为它是在当天在firebase上添加的
2 回答
您可以使用javascript Date对象进行数学运算,即