在 Firebase URL 中使用 Firebase 服务器时间戳
Use Firebase server timestamp in Firebase URL
我想在 Firebase URL 中使用 Firebase 服务器的当前时间。下面是我正在尝试完成的示例。
Firebase(url: "https://location.firebaseio.com/logs/<firebase_time_stamp>")
Firebase(url: "https://location.firebaseio.com/logs/" + Firebase.TIME_STAMP)
有办法吗?如果是这样,我需要它在 Swift 和 Java 中可行。我知道你小时候可以做这样的事情,但这不是我想要的。
Firebase 服务器端时间戳 (iOS, Android) 只能用于值,不能用于键。
我能想到的最接近的近似值是使用底层平台的客户端时间和 Firebase 跟踪的偏移量。 Rob 对此给出了很好的解释 here:
There is no way to get the server time synchronously from Firebase, but the local time + server offset time (provided immediately whenever you write to Firebase using the ServerValue) is a good approximation.
另请参阅 documentation that introduces /.info/serverTimeOffset
的这一部分。
对 swift 4.0 使用 ServerValue.timestamp()
。
let timeStamp = ServerValue.timestamp()
let str = "https://location.firebaseio.com/logs/\(timeStamp)"
我想在 Firebase URL 中使用 Firebase 服务器的当前时间。下面是我正在尝试完成的示例。
Firebase(url: "https://location.firebaseio.com/logs/<firebase_time_stamp>")
Firebase(url: "https://location.firebaseio.com/logs/" + Firebase.TIME_STAMP)
有办法吗?如果是这样,我需要它在 Swift 和 Java 中可行。我知道你小时候可以做这样的事情,但这不是我想要的。
Firebase 服务器端时间戳 (iOS, Android) 只能用于值,不能用于键。
我能想到的最接近的近似值是使用底层平台的客户端时间和 Firebase 跟踪的偏移量。 Rob 对此给出了很好的解释 here:
There is no way to get the server time synchronously from Firebase, but the local time + server offset time (provided immediately whenever you write to Firebase using the ServerValue) is a good approximation.
另请参阅 documentation that introduces /.info/serverTimeOffset
的这一部分。
对 swift 4.0 使用 ServerValue.timestamp()
。
let timeStamp = ServerValue.timestamp()
let str = "https://location.firebaseio.com/logs/\(timeStamp)"