I used childByAutoId()
save the timestamp as an auto-id. I can successfully retrieve the timestamp key that looks like -KJrs03bWbSTXfomqzMW
. When I check the key's type, it says AnyObject.
let timestamps = snap.value.allKeys
for timestamp in timestamps {
print(timestamp) // -KJrs03bWbSTXfomqzMW
if let t = timestamp as? NSTimeInterval {
print(NSDate(timeIntervalSince1970: t/1000))
print("true")
} else {
print("false")
}
}
However, it goes into false
bit.
What am I doing wrong? What is the proper way of converting Firebase timestamps to NSDate?
PS: I remember I read Firebase allows for a global timing for the items with this kind of timestamp. Is there a way that would enable me to get human-readable version of the time, such as 30mins ago, 5 hrs ago directly working with Firebase or should I use NSDateFormatter?
The node looks like:
- -KJrs03bWbSTXfomqzMW
- "key1": "val"
- "key2": "val"