Javascript Firebase:将实时数据库时间戳转换为firestore时间戳的代码/公式?

Javascript Firebase:将实时数据库时间戳转换为firestore时间戳的代码/公式?,javascript,firebase,firebase-realtime-database,google-cloud-firestore,Javascript,Firebase,Firebase Realtime Database,Google Cloud Firestore,我在Firebase上运行一个web应用程序,从实时数据库开始,现在我正在将数据迁移到firestore 我使用ADMINSDK迁移了除时间戳之外的所有其他数据。在我的web应用程序中,当用户上传新内容时,代码会向数据库添加时间戳,以便内容可以按时间排序 问题在于实时数据库和firestore显然在记录时间戳时使用了不同的方法: firebase.database.ServerValue.TIMESTAMP // This will be in the following format: 157

我在Firebase上运行一个web应用程序,从实时数据库开始,现在我正在将数据迁移到firestore

我使用ADMINSDK迁移了除时间戳之外的所有其他数据。在我的web应用程序中,当用户上传新内容时,代码会向数据库添加时间戳,以便内容可以按时间排序

问题在于实时数据库和firestore显然在记录时间戳时使用了不同的方法:

firebase.database.ServerValue.TIMESTAMP // This will be in the following format: 1577778747131 
firebase.firestore.Timestamp.now() // This will be in the following format: December 31, 2019 at 4:52:00 PM UTC + 9
另一个问题是firebase.firestore.Timestamp.now显然不是以毫秒或纳秒为单位存储的,而是以系统中的实际日期和时间为单位存储的。因此,我不知道在写入firestore而不是firebase.firestore.Timestamp.now时,要输入什么值(如果有)

在Javascript中,将时间戳值从实时数据库转换为firebase时间戳的代码是什么?基本上,下面的空白代码是什么:

postinfo.forEach(pi=>{
   const a = pi.time; //Timestamp stored  in realtime database format.
   /*
   Code to transform the timestamp in realtime database to the format to be uploaded to firestore. This I don't know yet.
   */
   const b = new_time;
   // Some code to log the new time instead of the old time. This I can take care of.

我可以花时间使用一个在线可用的转换器,并以新的格式手动记录时间,但这需要几个小时,这不是程序员想要做的事情。有关于如何执行此操作的建议吗?

您将在实时数据库中指定为ServerValue.timestamp的服务器时间戳在Firestore中称为

Firestore中的时间戳不像实时数据库那样以毫秒为单位存储为unix时间。它们使用两个数字存储,偏移量以秒和纳秒为单位,如API文档中所述。从Firestore中读取时间戳类型字段时使用该时间戳对象


阅读有关Firestore服务器时间戳如何工作的详细信息。

您将在实时数据库中指定为ServerValue的服务器时间戳。时间戳在Firestore中称为

Firestore中的时间戳不像实时数据库那样以毫秒为单位存储为unix时间。它们使用两个数字存储,偏移量以秒和纳秒为单位,如API文档中所述。从Firestore中读取时间戳类型字段时使用该时间戳对象

了解有关Firestore服务器时间戳在中的工作方式的更多信息