You are using unix timeStamp*1000 which when casted to Int is used as a timestamp, but since you are going to use it for time manipulations. use this to store your timestamp:-
let timeStamp = NSDate.timeIntervalSinceReferenceDate // Like this only
Make an extension of NSDate outside your class scope
extension NSDate {
func daysFromTheDate(date: NSDate) -> Int {
return NSCalendar.currentCalendar().components(.Day, fromDate: date, toDate: self, options: []).day
}
}
class yourViewController : UIViewController,.. {
...
}
Declaration:-
let date1 = NSDate() // Declare the variable globally
Then in your .observe event firebase function use this: -
var retrieved_timeStamp = ... // timeStamp that you retrieve from firebase
var date = NSDate(timeIntervalSinceReferenceDate: timeInterval(retrieved_timeStamp))
print(date1.daysFromTheDate(from: date as NSDate))
Check Condition
if date1.daysFromTheDate(from: date as NSDate) >= 2{
//48 or more hours have passed now, Do the Job. Bingo!..
}
For further date manipulation look up :- Difference between two NSDates