Tri*_*iFu 16 javascript datetime firebase
我是Firebase的新手,我想知道如何存储JavaScript日期并使用Firebase稍后在客户端进行比较?
我想做的事情如下:
var someDate = new Date();
myRootRef.set(someDate);
myRootRef.on('value', function(snapshot) {
var currDate = new Date();
if (currDate >= snapshot.val()){
//do something
}
Run Code Online (Sandbox Code Playgroud)
但是,我null从快照中获取了一个值?
gho*_*ost 20
您还可以使用时间戳.
var timestamp = new Date().getTime();
myRootRef.set(timestamp);
myRootRef.on('value', function(snapshot) {
var currDate = new Date();
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: " + new Date(snapshotTimestamp));
if (currDate >= new Date(snapshotTimestamp)){
//do something
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16878 次 |
| 最近记录: |