树莓派 - 恢复时间戳问题



所以在我的项目中,我试图将时间戳发送到我的firestore数据库。当我在python代码中测试我的日期时间时,它会给我正确的日期和时间,将数据发送到firestore后,数据库中的时间戳数据始终与当前时间起+8小时

从 2018-05-20 07:11:19.833275 到 2018-05-20 15:11:19.833275

其他一切都是正确的,甚至是时区,只有小时除外。顺便说一下,我们的时区是UTC+8。 我不明白我做错了什么。

这是我的代码:

import firebase_admin
from firebase_admin import credentials
from google.cloud import firestore
from firebase_admin import firestore
import datetime, sys
now = datetime.datetime.now()
# Use a service account
cred = credentials.Certificate('*some key*')
firebase_admin.initialize_app(cred)
db = firestore.client()
path = db.collection("*somepath*")
doc_ref = path.document()
doc_ref.set({
'date': now,
'rate': 60,
'used': 1
})

print ("current: %s" %now)

要获得更一致的时间戳,请考虑使用 FirestoreSERVER_TIMESTAMP常量:

doc_ref.set({
'date': firestore.SERVER_TIMESTAMP,
'rate': 60,
'used': 1
})

https://google-cloud-python.readthedocs.io/en/latest/firestore/constants.html

然后,如果需要,可以在客户端转换时间戳。

最新更新