【发布时间】:2016-05-25 02:03:49
【问题描述】:
我正在开发 ios,我发现很难检查两个 NSDate 是否来自同一天。我试过用这个
fetchDateList()
// Check date
let date = NSDate()
// setup date formatter
let dateFormatter = NSDateFormatter()
// set current time zone
dateFormatter.locale = NSLocale.currentLocale()
let latestDate = dataList[dataList.count-1].valueForKey("representDate") as! NSDate
//let newDate = dateFormatter.stringFromDate(date)
let diffDateComponent = NSCalendar.currentCalendar().components([NSCalendarUnit.Year, NSCalendarUnit.Month, NSCalendarUnit.Day], fromDate: latestDate, toDate: date, options: NSCalendarOptions.init(rawValue: 0))
print(diffDateComponent.day)
但它只是检查两个 NSDate 是否相差 24 小时。我认为有一种方法可以让它工作,但我仍然希望在凌晨 2 点之前将 NSDate 值算作前一天,所以我在这里肯定需要一些帮助。谢谢!
【问题讨论】: