如何从iOS Swift的Firebase Timestamp中删除时间



我如何检查我的"时间戳"值是否比当前时间大一天并从firebase删除条目?例如,我怎么知道1480561776458是否在24小时前?

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)

这是我用来创建时间戳记的时间。如果用户创建了某些内容,则帖子(创建的用户)将对响应(由其他用户)进行24小时的响应(由其他用户)处于活动状态。这可能不是您想要的,但应该帮助您朝这个方向前进。

完成时间戳的内容后,只需将命令发送到Firebase DB以删除条目,一旦经过一定的时间。

最新更新