姬長信(Redy)

java – Firebase Firestore上的ServerTimestamp始终…


我正在尝试使用Firebase Firestore在Android客户端中添加时间戳字段.

根据documentation

Annotation used to mark a Date field to be populated with a server
timestamp. If a POJO being written contains null for a
@ServerTimestamp-annotated field, it will be replaced with a
server-generated timestamp.

但是当我尝试时:

@ServerTimestamp
Date serverTime = null; // I tried both java.util.Date and java.sql.Date

//...

Map msg = new HashMap();
// ... more data
msg.put("timestamp", serverTime);

在Cloud Firestore数据库中,此字段始终为null.