开发者

iPhone SDK Date Format [duplicate]

This question already has answers here: Closed 11 years ago.

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]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜