如何从Firebase timeStamp获取当前数据

时间:2018-05-08 08:19:54

标签: javascript firebase firebase-realtime-database google-cloud-firestore

我在数据对象中使用ServerTimeStamp,现在我只想检索当前数据。

var happycount =  admin.database().ref(`/tariq-road/happy`)
    .orderByChild('timeStamp')
    .equalTo(Date.now())
    .once('value', (snapshot) => {
      var data = snapshot.numChildren()
      console.log('data:  ', data)
    })

如何获取今天的数据?

1 个答案:

答案 0 :(得分:1)

var start = new Date();
start.setHours(0,0,0,0);

var end = new Date();
end.setHours(23,59,59,999);

var happycount =  admin.database().ref(`/tariq-road/happy`)
    .orderByChild('timeStamp')
    .startAt(start.valueOf())
    .endAt(end.valueOf())
    .once('value', (snapshot) => {
      var data = snapshot.numChildren()
      console.log('data:  ', data)
    })