Charles Jr
Charles Jr

Reputation: 9149

How to delete time from Firebase timestamp in ios swift?

How can I check to see if my "timestamp" value is a day older than the current time and delete the entry from Firebase? As example how would I know if 1480561776458 was more than 24 hours ago?

Upvotes: 0

Views: 368

Answers (1)

Ro4ch
Ro4ch

Reputation: 850

let components = DateComponents()
let startDate = Date(timeIntervalSince1970:addServerStamp/1000)
let roundTimeLeft = startDate.addingTimeInterval(60*60*24)
let currentDate = Date()
let calendar = Calendar.current
    components = calendar.dateComponents([.hour, .day, .minute, .second], from: currentDate , to: roundTimeLeft)

This is what I used to create the time left from a time stamp. If the user created something, the post(the user created) would be active for responses(by other users) for 24hours after the post. This might not be exactly what you are looking for but it should help you go in that direction.

Once you get your timestamp stuff handled it is just a matter of sending the command to firebase DB to delete the entry once a certain amount of time has passed.

Upvotes: 1

Related Questions