NSString *dateString = @"Feb 23, 2014";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM dd, yyyy"];
NSDate *date = [dateFormatter dateFromString:dateString];
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
NSString *newDateString = [dateFormatter stringFromDate:date];
how to convert nsdate to another format using nsdateformatter
-
15-10-2022 - |
Pergunta
I have date string in this format Feb 23, 2014 coming from web services, I want to convert it to this format 02-23-2014, I am trying a lot but all the time nsstring return me null value
NSDateFormatter *DateFormatter=[[NSDateFormatter alloc] init];
[DateFormatter setDateStyle:NSDateFormatterMediumStyle];
[DateFormatter setDateFormat:@"MM-dd-yyyy"];
// date formatter two
NSDate *dateVal = (NSDate *)bookDetail.classdate;
NSLog(@"date %@",dateVal);
NSString *dateTwo = [DateFormatter stringFromDate:dateVal];
NSLog(@"new date string %@",dateTwo);
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow