Firebase TIMESTAMP to date and Time

后端 未结 18 2548
温柔的废话
温柔的废话 2020-11-27 03:39

I am using firebase for my chat application. In chat object I am adding time stamp using Firebase.ServerValue.TIMESTAMP method.

I need to show the messa

18条回答
  •  -上瘾入骨i
    2020-11-27 03:51

    For those looking for the Firebase Firestore equivalent. It's

    firebase.firestore.FieldValue.serverTimestamp()
    

    e.g.

    firebase.firestore().collection("cities").add({
        createdAt: firebase.firestore.FieldValue.serverTimestamp(),
        name: "Tokyo",
        country: "Japan"
    })
    .then(function(docRef) {
        console.log("Document written with ID: ", docRef.id);
    })
    .catch(function(error) {
        console.error("Error adding document: ", error);
    });
    

    Docs

提交回复
热议问题