我有一個非常奇怪的錯誤。我有一些帶有日期列的事件資料。當我使用 Python 代碼將資料推送到 Firestore 資料庫時,它會將日期向后移動一天。
所以我的資料在我的 Python 筆記本中看起來像這樣

我通過匯出到 CSV 進行了雙重檢查

但是在我的 Firestore 控制臺中,該日期顯示為:

這些是我用來上傳到 Firestore 的 Python 函式:
def batch_data(iterable, n=1):
l = len(iterable)
for ndx in range(0, l, n):
yield iterable[ndx:min(ndx n, l)]
def write_to_firestore(data):
store = firestore.client()
collection_name = "events"
for batched_data in batch_data(data, 499):
batch = store.batch()
for data_item in batched_data.iterrows():
doc_ref = store.collection(collection_name).document()
batch.set(doc_ref, data_item[1].to_dict())
batch.commit()
return None
write_to_firestore(events_df)
對于我的一生,我無法弄清楚為什么它可能會在某一天將日期推遲。
uj5u.com熱心網友回復:
我們需要查看您傳遞給 Firestore 的確切資料,但這很可能是由于時區偏移發生了變化。
您可能會在本地時間為您的計算機撰寫Timestamp欄位(包括日期和時間),然后 Firestore 將其轉換為 UTC-8/太平洋時間(如您在螢屏截圖中所見)。如果您讀取該值,它實際上會將其轉換回您的本地時區。
如果您希望日期保持在您的代碼中,請務必將其設定為 UTC。只需準備在讀取時將其視為 UTC,因為 Firestore SDK 也可能會在本地時區回傳它。
uj5u.com熱心網友回復:
當某處的時區設定之一設定錯誤時,這是??一種典型的綜合癥。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/401550.html
上一篇:自動過濾器不回傳任何行,因此可見范圍什么都不是,但過濾后的可見范圍不是什么
下一篇:Firebase:使用FieldPath.documentId()使用多個“orderBy”和“orderBy”進行分頁
