小编Pra*_*mar的帖子

如何在android中使用FieldValue.serverTimestamp()来自定义模型类

我使用Firestore作为数据库,现在我想在用户注册时存储服务器时间戳.

来自Firestore doc

  Map<String,Object> updates = new HashMap<>();
  updates.put("timestamp", FieldValue.serverTimestamp());
  docRef.update(updates)
  .addOnCompleteListener(new OnCompleteListener<Void>() {  //-- }
Run Code Online (Sandbox Code Playgroud)

但现在我想在我的模型课中加上这个时间戳.

public class UserModel implements Serializable {
    private String name;
    private String uid;
    private String email;
    private String password;
    private long timestamp;

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-realtime-database google-cloud-firestore

2
推荐指数
1
解决办法
3215
查看次数