下面是代码:
func firebaseTimestampSet(){
guard let currentUid = Auth.auth().currentUser?.uid else {return}
let ref = Firestore.firestore().collection("dateTest").document(currentUid)
ref.setData(["timestamp": FieldValue.serverTimestamp()])
}
结果如下:
正如您将在文档中读到的:
时间戳表示与任何时区或日历无关的时间点,表示为秒和秒的分数,以UTC历元时间的纳秒分辨率表示。
如果您在Firebase控制台中看到“the local time is display in the document”,这是因为Firebase控制台使用您计算机的时区配置来显示您本地时间中的时间戳值。
最后:
FieldValue.ServerTimeStamp()
,已经是这样了,它存储在UTC中”。