Javascript 如何将对象时间戳转换为firebase时间戳?

Javascript 如何将对象时间戳转换为firebase时间戳?,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我想转换以下时间戳: Object { "_nanoseconds": 725000000, "_seconds": 1621386976, } t { "nanoseconds": 725000000, "seconds": 1621386976, } 对于此时间戳: Object { "_nanoseconds": 725000000, "_seconds&quo

我想转换以下时间戳:

Object {
 "_nanoseconds": 725000000,
 "_seconds": 1621386976,
}
t {
  "nanoseconds": 725000000,
  "seconds": 1621386976,
}
对于此时间戳:

Object {
 "_nanoseconds": 725000000,
 "_seconds": 1621386976,
}
t {
  "nanoseconds": 725000000,
  "seconds": 1621386976,
}
我该怎么做呢?我被难住了。我尝试了
toDate()
及其变体,但没有任何效果。

在reddit上找到了以下内容:

getTimeText = (timeObject: any) => {
    // Convert to time text once it's of type firestore.Timestamp
    const getTextFromTimestamp = (timestamp: app.firestore.Timestamp) => {
        return this.timeAgo.format(timestamp.toDate())

    }
    if (timeObject instanceof app.firestore.Timestamp) {
        // Check if Timestamp (accessed from client SDK)
        return getTextFromTimestamp(timeObject)
    } else if (Object.prototype.toString.call(timeObject) === '[object Object]') {
        // Check if it's a Map (accessed from Cloud Functions)
        const seconds = timeObject['_seconds']
        const nanoseconds = timeObject['_nanoseconds']
        if (seconds && nanoseconds) {
            const timestamp = new app.firestore.Timestamp(seconds, nanoseconds)
            return getTextFromTimestamp(timestamp)
        }
    }
    console.log('Couldn\'t parse time', timeObject)
    // Fallback
    return 'some time ago'
}