【发布时间】:2021-03-28 04:56:47
【问题描述】:
我有这个 Firebase 函数来增加一些统计数据(它已经被削减了一点,但不会影响我的问题):
exports.processRecordEventStat = functions.https.onCall(async (data, context) => {
const n = new Date();
const d = new Date(n.getFullYear(), n.getMonth());
console.log(d);
//Add to aggregate stats
let aggStatDoc = await admin.firestore().collection('businesses').doc(businessid).collection('aggregatestats').doc(`${d.getFullYear()}-${d.getMonth() + 1}`).get();
if (aggStatDoc.exists)
return aggStatDoc.ref.update({ [stat]: firestore.FieldValue.increment(1), date: d });
else
return aggStatDoc.ref.set({ [stat]: 1, date: d });
});
当这个函数运行时,我在控制台中看到这个日志并且日期看起来是正确的(当前日期精确到月份):
为什么日期存储在文档中后一个月?
【问题讨论】:
-
您碰巧选择了当月的最后一天。显示一个相对于您当地时区的日期(仍然是 2 月 28 日);另一个关于格林威治标准时间(结束到 3 月 1 日)。因此,“月”差异:) 完全相同的日期/时间 - 只是两种不同的“显示”表示。
标签: node.js firebase google-cloud-firestore google-cloud-functions