我试图使用云功能在防火墙中创建一个新文档。但是,我无法将日期保存为时间戳,而是将其保存为当前的字符串。
现在是怎么回事,

我需要什么来实现

我的云函数片段
await admin.firestore()
.doc('/buyerProfile/'+response.buyerId)
.collection('notifications')
.add({
'type':'New response',
'responseId':response.responseId,
'requestId':response.requestId,
'date': Date(Date.now()),
'compressedImgUrl':response.compressedImgUrl,
'description':response.description,
'requestPaidFor':request.data().isPaidFor
}).then(()=>console.log('Notification created'));发布于 2021-09-23 09:21:29
可以用来获得时间戳new Date().getTime();。
发布于 2021-09-23 09:21:48
在new构造函数之前没有Date关键字,它确实会返回一个字符串。如果您想要日期对象,请尝试如下:
date: new Date() // Date object of current time如果要将时间戳存储为数字,则传递Date.now()
可以在浏览器控制台中检查相同的内容:

您还可以使用serverTimestamp()方法代替:
date: admin.firestore.FieldValue.serverTimestamp()发布于 2021-09-23 09:29:14
就这样做吧:
let today = new Date();
let timestamDate = Date.parse(today) / 1000;你的约会日期将被转换为时间戳
https://stackoverflow.com/questions/69297223
复制相似问题