使用我的方法...
-(NSString *)changeDateFormat:(NSString*)stringDate dateFormat:(NSString*)dateFormat getwithFormat:(NSString *)getwithFormat{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:dateFormat];
NSDate *date = [dateFormatter dateFromString:stringDate];
dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:getwithFormat];
NSString *convertedString = [dateFormatter stringFromDate:date];
NSLog(@"Converted String : %@",convertedString);
return convertedString;
}
像下面这样使用它...
NSString *strSDate = [self changeDateFormat:@"2013-04-09 15:57:17" dateFormat:@"yyyy-MM-dd HH:mm:ss" getwithFormat:@"dd/MM/yyyy"];
NSLog(@"ex date == %@",strSDate );
它会打印..
前日期 == 09/04/2013
见我的博客...