Firebase 2.0 - Store Date and Timezone

前提是你 提交于 2019-12-25 07:35:06

问题


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?

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?


回答1:


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)


来源:https://stackoverflow.com/questions/38168085/firebase-2-0-store-date-and-timezone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!