firestore时间戳的JavaScript日期

firestore时间戳的JavaScript日期,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我有一个带有datepicker的表单,它存储的日期类似于“1559389274032” 有没有办法将其转换为firestore时间戳?了解firestore时间戳格式: 如果您已导入firebase sdk。。。。。然后你可以试试这个: let d=new Date(milliseconds) //pass in your milliseconds, this will return the js date object let timestamp=firebase.firestore.Ti

我有一个带有datepicker的表单,它存储的日期类似于“1559389274032”


有没有办法将其转换为firestore时间戳?

了解firestore时间戳格式:

如果您已导入firebase sdk。。。。。然后你可以试试这个:

let d=new Date(milliseconds) //pass in your milliseconds, this will return the js date object
let timestamp=firebase.firestore.Timestamp.fromDate(d)

要了解firestore时间戳格式,请执行以下操作:

如果您已导入firebase sdk。。。。。然后你可以试试这个:

let d=new Date(milliseconds) //pass in your milliseconds, this will return the js date object
let timestamp=firebase.firestore.Timestamp.fromDate(d)

试着这样做:

var myDate = firebase.firestore.Timestamp.fromDate(new Date());
其中new Date()将是时间戳构造函数

此外,我99%确定您甚至不需要它,这应该将值保存为日期,只是确保您不将其转换为字符串

ref.update({ created_at: new Date() })

试着这样做:

var myDate = firebase.firestore.Timestamp.fromDate(new Date());
其中new Date()将是时间戳构造函数

此外,我99%确定您甚至不需要它,这应该将值保存为日期,只是确保您不将其转换为字符串

ref.update({ created_at: new Date() })

你说得对,添加为JavaScript日期很简单!你说得对,添加为JavaScript日期很简单!这是因为
firebase.firestore.Timestamp.fromDate(d)
前面不应该有
new
。这是因为
firebase.firestore.Timestamp.fromDate(d)
前面不应该有
new