【发布时间】:2018-11-15 22:26:52
【问题描述】:
我有这个代码:
func getSystemDate()-> String{
let date = Date()
let calendar = Calendar.current
let hour = String(format: "%02d",calendar.component(.hour, from: date))
let minutes = String(format: "%02d",calendar.component(.minute, from: date))
let seconds = String(format: "%02d",calendar.component(.second, from: date))
let day = String(format: "%02d",calendar.component(.day, from: date))
let month = String(format: "%02d",calendar.component(.month, from: date))
let year = String(format: "%02d",calendar.component(.year, from: date))
let fullDate = "\(year)-\(month)-\(day) \(hour):\(minutes):\(seconds)"
return fullDate
}
let date1 = getSystemDate()
let date2 = "2018-05-23 13:14:47"
if date1 > date2 {
print("its ok - update available")
} else {
print("wrong - you have actually database")
}
我的函数getSystemDate() 以字符串形式返回实际日期。
在变量date2 - 我有数据库更新日期。
我需要确定是否可以更新数据库并将当前日期与可用数据库的日期进行比较:...
如何比较这些日期?
【问题讨论】:
标签: ios swift date swift3 swift4