how to use FieldValue.serverTimestamp() to custom model class in android

前端 未结 4 1973
北海茫月
北海茫月 2021-01-18 07:04

I am using Firestore as a database and now i want to store server timestamp when user register.

from the Firestore doc

  Map up         


        
4条回答
  •  感情败类
    2021-01-18 07:50

    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

提交回复
热议问题