Skip to content Skip to sidebar Skip to footer

How To Save Timestamp In Firestore?

I am working on a chat app and I want to store timestamp of my messages. My Data Class for Messages is: import com.google.firebase.firestore.ServerTimestamp; import java.util.Dat

Solution 1:

To solve this, you should remove the Date time as the argument of your constructor. Your constructor should be like this:

public messgaesDataClass(String messageText, int messageStatus, String messagefrom) {
    this.messageText = messageText;
    this.messageStatus = messageStatus;
    this.messagefrom = messagefrom;
}

There is no need to initialize the time object in your constructor. Firebase servers will read your time field as it is a ServerTimestamp (because of the annotation), and it will populate that filed with the server timestamp accordingly.


Post a Comment for "How To Save Timestamp In Firestore?"