Currently , I am storing the dates in a NSArray, as I have to load the list of dates in custom drop down view, but can't able to do so because of the following issue.
Here is the code how I am trying to format the NSDate:-
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDate *today = [NSDate date];
NSInteger dc = [currentCalendar ordinalityOfUnit:NSDayCalendarUnit
inUnit:NSYearCalendarUnit
forDate:today];
datesArray = [[NSMutableArray alloc]init];
for (int index = 1; index <= dc; index++)
{
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:index];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:components];// Year is coming "0000" --log is: "0000-12-31 18:06:32 +0000"
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"MMMM dd yyyy"]; //updated
NSString *articleDateString = [formatter stringFromDate:date]; // getting- Jan 01 0001
[datesArray addObject: pickerItemTitle];
}
But I am not getting the desired output like "January 15 2013"
Also in NSDate I am getting something like this "0000-12-31 18:06:32 +0000", can anybody tell me why the year is coming "0000"