This is the database below. I need to take the 'caption' child which is a timestamp and convert it into date format in Xcode.
"UserS" : {
"K1eqsVZfKGgIf0sS1UZcPNxY62x1" : {
"Education" : "William Taft Elementary",
"PhotoPosts" : "https://firebasestorage.googleapis.com/v0/b/daylike-2f938.appspot.com/o/images%2FPhotoPosts?alt=media&token=fd92856e-f7d2-4558-82c4-ee49f580icc5e",
"caption" : 1563277511065,
"users" : "jane19@aol.com"
},
This is what I have under super view did load.
let databaseRef = Database.database().reference()
let uid = Auth.auth().currentUser!.uid
databaseRef.child("UserS").child(uid).child("caption").observeSingleEvent(of: .value, with: { (snapshot) in
guard let message = snapshot.value as? [String:String] else { return }
let caption = message["caption"]
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss.SSSSxxx"
guard let date = dateFormatter.date(from: caption!) else {
fatalError("ERROR: Date conversion failed due to mismatched format.")
}
if (snapshot.exists()){
print ("mmmmmmm")
}else{
print("badddddd")
}
})
At the end I want to print out the timestamp in date format so that I can check it it is 24 hours old.