iPhone SDK Date Format [duplicate]
Possible Duplicate:
How to change format of date/time?
In my program I'm making an API call for getting a date, but the received date has an incorrect format. It looks like 2011-07-06 00:00:00
. How I can change it to 6-july-2开发者_如何学Python011
?
You try my code that will help you because I run successfully.
NSString *dateStr = @"2011-07-06 00:00:00";
NSDateFormatter *dtF = [[NSDateFormatter alloc] init];
[dtF setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *d = [dtF dateFromString:dateStr];
NSDateFormatter *dateFormatStr = [[NSDateFormatter alloc] init];
[dateFormatStr setDateFormat:@"d-MMM-yyyy"];
NSString *strDate = [dateFormatStr stringFromDate:d];
NSLog(@"%@",strDate);
try this code..
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"dd-MMM-YYYY"];
NSString *dateStr = [formatter stringFromDate:[NSDate date]];
精彩评论