Firebase New Date()?
I'm new to Firebase and I was wondering how I can store a JavaScript date and use Firebase to compare them on the client side later? I want to do something like: var someDate = new
Solution 1:
You can also use timestamp.
var timestamp = newDate().getTime();
myRootRef.set(timestamp);
myRootRef.on('value', function(snapshot) {
var currDate = newDate();
var snapshotTimestamp = snapshot.val();
//you can operate on timestamps only...console.log("Snapshot timestamp: " + snapshotTimestamp);
if(currDate.getTime() >= snapshotTimestamp) {
//do something
}
//...or easily create date object with it console.log("Snapshot full date: " + newDate(snapshotTimestamp));
if (currDate >= newDate(snapshotTimestamp)){
//do something
}
});
Solution 2:
You need to set a Firebase with string or object with value, and than read the same value in the event.
var someDate = newDate();
myRootRef.set({Date: someDate.toString()});
myRootRef.on('value', function(snapshot) {
var msg = snapshot.val();
var currDate = newDate();
if (currDate >= msg.Date){
//do something
}
});
Post a Comment for "Firebase New Date()?"