Search code examples
iphoneobjective-cnsdate

ios:How to compare 2 NSdates with Different formats?


i faced a lot of problem while comparing two NSDate with different format though i am new to this.

-what should be the best approach to this problem?

1.I tried to convert this two dates in into one format and then go for comparison or Should i first Know the format of this two date then go for comparison


Solution

  • NSDate does not know any thing about it's format. Internally the date is stored without any format or region.

    To compare date you can use the compare: method.

    if([someDate compare:ortherDate] == NSOrderedDescending ){
       // someDate later then otherDate;
    }