Reputation: 172
What I want to do: Convert the current time of the user to a GMT timestamp and then upload it to firebase.
Problem: The timestamp in my Firestore database is not the GMT timestamp, but the regular one with the unique timezone of the user.
My code:
let formatter = DateFormatter()
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z"
let date = Date()
self.db.collection("posts").document(combined).setData([
"time": date,
]) { err in
if let err = err {
print("Error writing document: \(err)")
} else {
print("Post Document successfully written!")
print(date)
}
}
What actually happens so far:
I get 2020-06-26 17:57:40 +0000
when I print out the date after I uploaded to firebase. This is the timestamp I want to upload.
But once I check firebase I see:
What I tried:
Upvotes: 0
Views: 442
Reputation: 3658
Those two timestamps are actually the same. i.e. 19:57:40 in UTC+2 is the same as 17:57:40 in UTC+0.
So I suspect the issue is what's actually being displayed in the Firebase console. There's likely a setting somewhere that controls how dates are displayed.
Upvotes: 2