Firebase 2.0-存储日期和时区 [英] Firebase 2.0 - Store Date and Timezone

查看:182
本文介绍了Firebase 2.0-存储日期和时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将某个对象在Firebase数据库中创建的日期存储在日期中,我如何在Firebase中存储一个日期,该日期可以算出距该日期有多久了.我只是将NSDate存储在其中,但是时区又如何呢?

I need to store the date that something was created in the firebase database for a friend request, how can i store a date in firebase that i can work out how long ago since this date something happened. I would just store an NSDate in there but then what about timezones?

我不知道firebase是否具有类似于Parse这样的东西,它可以在其中自动存储创建的日期和时区,以便您可以从服务器读取它?

I dunno if firebase has something like Parse had where it would store date created and timezone automatically so you could read it from the server?

推荐答案

您需要自行设置! 我使用此代码进行时间戳记.希望这就是你想要的.

You need to set it up by yourself ! I use this code to do the timestamp. Hope this is what u want.

 let formatter = NSDateFormatter()
    formatter.dateFormat = "yyyy/MM/dd, H:mm:ss"
    let defaultTimeZoneStr = formatter.stringFromDate(NSDate())

let post = ["\(key)":["username": username, "userPhoto": userPhotoUrl, "postPhoto": downLoadURL,"postText": postText!,"User":FIRAuth.auth()!.currentUser!.uid, "time":defaultTimeZoneStr] ]

                self.DatabaseRef.child("posts").updateChildValues(post)

这篇关于Firebase 2.0-存储日期和时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆