我想比较两个NSDate,但每个日期都显示为“早于”todaysDate。有什么想法吗?
let compareResult = self.todaysDate.compare(self.date)
if compareResult == NSComparisonResult.OrderedDescending {
println("Today is later than date2")
} else {
println("Future")
}
获取"todaysDate"。
let todaysDate = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitMonth | .CalendarUnitYear | .CalendarUnitDay, fromDate: todaysDate)
let hour = components.hour
let minutes = components.minute
let month = components.month
let year = components.year
let day = components.day
println(todaysDate)
这个打印是:
2014-11-12 14:48:48 +0000
打印 "date" 的结果是:
2014-10-24 07:24:41 +0000
这是在Parse.com服务器上的内容。
谢谢
self.todaysDate
和self.date
的代码行吗? - Ron Fesslerprintln(self.date)
和println(self.todaysDate)
的输出将会很有帮助。 - Martin R