swift - Comparing NSDate -
i compare 2 nsdates every date shows being "earlier" todaysdate. ideas?
let compareresult = self.todaysdate.compare(self.date) if compareresult == nscomparisonresult.ordereddescending { println("today later date2") } else { println("future") }
to "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)
this print is:
2014-11-12 14:48:48 +0000
and print "date" is:
2014-10-24 07:24:41 +0000
this on parse.com server.
thanks
i think perhaps you're interpreting results of compare
backwards. check out. each of asserts
passes:
let today = nsdate() let tomorrow = today.datebyaddingtimeinterval(24 * 60 * 60) let yesterday = today.datebyaddingtimeinterval(-24 * 60 * 60) assert(today.compare(tomorrow) == .orderedascending) // today < tomorrow assert(today.compare(yesterday) == .ordereddescending) // today > yesterday assert(today.compare(today) == .orderedsame) // today == today
Comments
Post a Comment