ios - Check date if exist in this year or not in Objective c -


i googled , found many link compares 2 dates scenario bit different , unable found in google. want compare date either exist in year or not. have date in format. 2016-01-20t06:19:27 if below current year use format

[dateformat setdateformat:@"dd mmm yyyy"]; 

and if exist in year use

[dateformat setdateformat:@"dd mmm"]; 

(to remove year), , in future no chance date exist. need solutions on this.

 nsstring * date = [dictionary objectforkey:@"date"];  nsdateformatter *dateformat = [[nsdateformatter alloc] init];  [dateformat setdateformat:@"yyyy-mm-dd't'hh:mm:ss"];  nsdate *mydate = [dateformat datefromstring:date];   [dateformat setdateformat:@"yyyy"];   nsstring *stryear=[dateformat stringfromdate:mydate];    if([stryear isequaltostring:[dateformat stringfromdate:[nsdate date]]){      [dateformat setdateformat:@"dd mmm yyyy"];      nsstring *strdate=[dateformat stringfromdate:mydate];      nslog(@"%@",strdate);   }   else{     [dateformat setdateformat:@"dd mmm"];     nsstring *strdate=[dateformat stringfromdate:mydate];     nslog(@"%@",strdate);   } 

Comments