关于ZAKER 融媒体解决方案 合作 加入

如何使用 FieldValue.serverTimestamp ( ) 在 android 中自 .

CocoaChina 10-13

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

从 Firestore 文档中

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

但是现在我希望在我的模型课中使用这个时间戳 .

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 uid ) { this.uid = uid; } public String getEmail ( ) { return email; } public void setEmail ( String email ) { this.email = email; } public String getPassword ( ) { return password; } public void setPassword ( String password ) { this.password = password; }}

我怎么能做到这一点 .

请帮我 .

最佳答案

经过大量研究 , 我找到了解决方案 .

@ServerTimestamp private Date timestamp; public Date getTimestamp ( ) { return timestamp; } public void setTimestamp ( Date timestamp ) { this.timestamp = timestamp; }

当叫这个课时

UserModel userModel = new UserModel ( ) ;userModel.setEmail ( email ) ;userModel.setPassword ( password ) ;userModel.setName ( name ) ;userModel.setUid ( uid ) ;insertUserDataToFireStore ( userModel ) ;

这是我找到解决方案的链接

Click here

以上内容由"CocoaChina"上传发布 查看原文
相关标签 android

觉得文章不错,微信扫描分享好友

扫码分享