I am using Firestore as a database and now i want to store server timestamp when user register.
from the Firestore doc
Map up
You need to change this line of code:
private long timestamp;
with
private Map<String, String> timestamp;
And here are the corresponding public setters
and getters
:
public void setTimestamp(Map<String, String> timestamp) {
this.timestamp = timestamp;
}
public Map<String, String> getTimestamp() {
return timestamp;
}
Remember, that you are setting the timestamp as Map
and when you are retrieving, you are retrieving it as a Long
.
private com.google.firebase.Timestamp date;
public yourModel(com.google.firebase.Timestamp date) {
this.date= date;
}
public com.google.firebase.Timestamp getDate() {
return date;
}
public void setDate(com.google.firebase.Timestamp date) {
this.date = date;
}
If you only want a timestamp and not an accurate time event then you can use
System.currentTimeMillis();
After lots of research i found a solution for this.
@ServerTimestamp
private Date timestamp;
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
and when calling this class
UserModel userModel = new UserModel();
userModel.setEmail(email);
userModel.setPassword(password);
userModel.setName(name);
userModel.setUid(uid);
insertUserDataToFireStore(userModel);
This is the link where i found the solution Click here