无法将日期时间数据推送到 Firebase 实时数据库

Cannot push dateTime data into Firebase Realtime Database

这是 console.log(values) 的数据。

city: "abc"
departmentId: "humanResources"
email: "123@gmail.com"
facebook: ""
fullName: "afdasf"
gender: "male"
hireDate: Fri Aug 06 2021 21:30:00 GMT+0630 (Myanmar Time) {}
__proto__: Object
isPermanent: true
mobile: "65689189789"
otherDepartment: ""
university: "abcde"
__proto__: Object

但是当我将数据推送到 firebase 时,我得到了除 hireDate 之外的所有其他数据。我使用“@date-io/date-fns”反应库中的 DateFnsUtils 来获取日期。这是来自 firebase 的数据。

city: "abc"
departmentId: "humanResources"
email: "123@gmail.com"
facebook: ""
fullName: "afdasf"
gender: "male"
isPermanent: true 
mobile: "65689189789"
otherDepartment: ""
university: "abcde"

乍一看,您的 hireDate 属性 似乎是一个 Date 对象。虽然这是一个有效的 JavaScript 对象,但它 不是 一个有效的 JSON 对象并且 Firebase 实时数据库只能存储 JSON 个对象。

解决这个问题的惯用方法是存储数据的时间戳,即自纪元以来的毫秒数。您可以通过调用 getTime() methodDate 中获取此值。