I have retrieved few dates from an array ,which where stored in string format in an array,now again I want to change the date time to OO:OO:OO when I retrieve it and get only the date without time..My code is as below
for(int i = 0 ; i<[keys count]; i++)
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeStyle = NSDateFormatterNoStyle;
dateFormatter.dateFormat = @"dd-MMM-yyyy";
NSDate *noteDate = [dateFormatter dateFromString:[keys objectAtIndex:i]];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit)fromDate:[NSDate date]];
NSInteger year = [weekdayComponents year];
//NSInteger month = [weekdayComponents month];
[gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
NSDateComponents *timeZoneComps=[[NSDateComponents alloc] init];
[timeZoneComps setYear:year];
[timeZoneComps setHour:00];
[timeZoneComps setMinute:00];
[timeZoneComps setSecond:01];
NSDate *noteDate1 =[gregorian dateFromComponents:timeZoneComps];
[self saveNotes:0 :noteDate1 :notes];
NSLog(@"dates:%@",noteDate);
}
Whether I am doin the correct way or I am missing something,please friends,help me out..
Regards
Ranjit
Set the date format to
also comment out this line
and try again