【发布时间】:2017-04-02 03:47:43
【问题描述】:
如何在 Swift 3 中比较两个日期? 我为其他 Swift 版本找到了许多解决方案,但它们对我不起作用。
let clickedDay:String = currentcell.DayLabel.text!
let currentDate = NSDate()
let currentDay = "" //want the current day
let dateFormatter = DateFormatter()
var dateAsString = ""
if Int(clickedDay)! < 10 {
dateAsString = "0" + clickedDay + "-11-2016 GMT"
}
else {
dateAsString = clickedDay + "-11-2016 GMT"
}
dateFormatter.dateFormat = "dd-MM-yyyy zzz"
let clickedDate = dateFormatter.date(from: dateAsString)
if currentDate as Date >= clickedDate! as Date {
return true
}
else {
//Want to get the days between the currentDate and clickedDate
let daysLeft = ""
}
我比较了两个日期,但我想要两个日期之间的日期。 有人可以帮我吗? 谢谢和问候
添加: 如果我有日期 22.11.2016 和 currentdate(现在 18.11.2016),我想要这之间的天数(在本例中为 4)
【问题讨论】:
标签: swift xcode swift3 nsdate date-comparison