<分区>
我正在从事 ios 开发,我发现很难检查两个 NSDates 是否来自同一天。我试着用这个
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)
但它只是检查两个 NSDates 是否有 24 小时的差异。我认为有一种方法可以让它工作,但我仍然希望在凌晨 2 点之前将 NSDate 值算作前一天,所以我在这里绝对需要一些帮助。谢谢!