2015-04-19 69 views
4

我想在Firebase网址中使用Firebase服务器的当前时间。下面是我想要完成的一个例子。在Firebase网址中使用Firebase服务器时间戳

Firebase(url: "https://location.firebaseio.com/logs/<firebase_time_stamp>") 
Firebase(url: "https://location.firebaseio.com/logs/" + Firebase.TIME_STAMP) 

有没有办法做到这一点?如果是这样,我需要它在Swift和Java中可行。我知道你可以像孩子一样做这样的事情,但那不是我想要的。

+0

您好!这看起来像[XY问题](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378)。如果您从问题集的详细描述以及您已排除的任何约束/方法开始,它可能会节省大量时间和精力。 – Kato

回答

3

Firebase服务器端时间戳(iOS,Android)只能在值中使用,而不能在键中使用。

我能想到的最接近的近似方式是使用底层平台的客户端时间和Firebase保留的偏移量。罗布给出了here的一个很好的解释:

有没有办法从火力地堡得到服务器的时间同步,但本地时间+服务器偏移时间(只要你写使用ServerValue到火力立即提供)一个很好的近似值。

另请参阅本节中的documentation that introduces /.info/serverTimeOffset

0

使用ServerValue.timestamp()为swift 4.0。

let timeStamp = ServerValue.timestamp() 

let str = "https://location.firebaseio.com/logs/\(timeStamp)"