Today one of my client report a bug that one of the application functionality suddenly stop work. After I unit-test the functionality, I come to know that NSDateFormatter is converting a wrong date. May be you had also experienced the same. below is my code
self.frmt2=[[NSDateFormatter alloc]init];
[self.frmt2 setDateFormat:@"YYYY-MM-dd”];
self.str_DateTogetData=[self.frmt2 stringFromDate:[NSDate date]];
If my system date is between 29-12-2014,30-12-2014,31-12-2014, then after converting date into string its shows 29-12-2015,30-12-2015,31-12-2015 but if my system date is not between these three dates then above code convert NSDate into string correctly.but if I am using below code then its converting NSDate into string correctly
self.frmt2=[[NSDateFormatter alloc]init];
[self.frmt2 setDateFormat:@"yyyy-MM-dd”];
self.str_DateTogetData=[self.frmt2 stringFromDate:[NSDate date]];
My problem is solved but I am in seek of knowledge why its happen. Any one have answer of it.