【发布时间】:2020-10-14 11:57:09
【问题描述】:
我在 firebase“cloud firestore”中有这个字段 firebase date field
在我想提取的云函数中(仅从该日期获取年份,仅获取年份和月份)
const year = BookedSessionChanges.bookedAt.toDate();
console.log("yearr ", year);
const month = BookedSessionChanges.bookedAt.toDate();
console.log("month ", month);
这是云函数中的代码,我使用 toDate() 将上图中显示的日期转换为旁边的 2020-10-06T08:38:14.066Z 时间。
那么我怎样才能从这个日期只得到年份和月份呢? Ps. 我尝试了 getYear() 和 toDate("Y") ...但这些都不起作用。
有什么帮助吗?谢谢
【问题讨论】:
标签: javascript typescript firebase date google-cloud-firestore