【发布时间】:2019-12-02 01:25:06
【问题描述】:
尝试从 javascript 日期转换为 firestore 时间戳
TypeError: Cannot read property 'Timestamp' of undefined
我尝试了两种方式:
- 使用 firebase-admin
const 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));
日期在new Date中用作参数的格式如下:“2017-01-29”。
预期结果:firestore 时间戳。
实际结果:TypeError: Cannot read property 'Timestamp' of undefined
注意:db 和 firebase 均为 null 或未定义。
是否有从 javascript 日期对象创建 Firestore 时间戳的明确方法?
【问题讨论】:
标签: javascript firebase google-cloud-firestore timestamp