ios - Comparing Date and Time Object -
this question has answer here:
- how compare 2 nsdates: more recent? 13 answers
i working method , not giving me proper output came know, way comparing date , time object wrong. googled not find relevant solution. want compare date , time object object.
for example:
if (dtcur >= dtstart && dtcur <= mydt) // 2014-03-24 11:30:00 >= 2014-03-24 11:00:00 & 2014-03-24 11:30:00 <= 2014-03-25 11:00:00 { // should come here in if condition }
but goes in else. means comparison wrong, can me how compare 2 date , time objects. in advance
many objects, including nsdate, have compare:
method. use so:
if ([date1 compare:date2] == nsorderedascending) { // date2 after date1 } else if ([date1 compare:date2] == nsordereddescending) { // date2 before date1 } else if ([date1 compare:date2] == nsorderedsame) { // they're both same date }
Comments
Post a Comment