試圖從 javascript 日期轉(zhuǎn)換為 firestore 時(shí)間戳拋出TypeError: Cannot read property 'Timestamp' of undefined我以兩種方式嘗試過:使用 firebase-adminconst admin = require('firebase-admin');const db = admin.firestore();const timestamp = db.Timestamp.fromDate(new Date(date));使用 firebase.firestore:const firebase = require('firebase');const timestamp = firebase.firestore.Timestamp.fromDate(new Date(date));日期用作設(shè)置了一個(gè)param新日期的格式如下:“2017年1月29日”。預(yù)期結(jié)果:firestore 時(shí)間戳。實(shí)際結(jié)果:類型錯(cuò)誤:無法讀取未定義的屬性“時(shí)間戳”注意:db 和 firebase 為 null 或未定義。是否有從 javascript 日期對(duì)象創(chuàng)建 firestore 時(shí)間戳的明確方法?
如何使用firebase-admin在firestore中將日期保存為時(shí)間戳?
桃花長(zhǎng)相依
2021-08-20 10:05:21