Firebase new Date()?

后端 未结 2 466
广开言路
广开言路 2020-12-14 18:42

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:

2条回答
  •  Happy的楠姐
    2020-12-14 19:14

    You need to set a Firebase with string or object with value, and than read the same value in the event.

        var someDate = new Date();
        myRootRef.set({Date: someDate.toString()});
    
        myRootRef.on('value', function(snapshot) {
        var msg = snapshot.val();
         var currDate = new Date();
        if (currDate >=  msg.Date){
         //do something
        }
        });
    

提交回复
热议问题