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?
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)