I have a angular app in which i am storing records to firebase with the timestamp using firebase.database.ServerValue.TIMESTAMP
Now i want to check if the timestamp added to the database exceeds five minutes.
I tried using moment in my Component but it just dosent work . It is giving false data . I guess the data stored in Firebase is in epoch where as i am in india so how to make moment work in Angular .
I am using Angular 2 Moment.
This is what i tried
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)));
}
The Value of this.comments when using it in date
let ts = new Date(this.comments[0].createdAt * 1000);
= Wed Aug 05 49474 20:09:20 GMT+0530 (India Standard Time)
where as for now its like -- Tue Jul 04 2017 14:56:46 GMT+0530 (India Standard Time)
Please help why its the comments data not is sink with the time it should be july 3 as it was added on that day on firebase
You can use the javascript Date object to do the math, i.e.