Eli
Eli

Reputation: 768

Firebase 2.0 - Store Date and Timezone

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?

Upvotes: 0

Views: 1262

Answers (1)

Johnny  Hsieh
Johnny Hsieh

Reputation: 856

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)

Upvotes: 1

Related Questions