日期格式问题 - 以MMM d,yyyy格式将字符串转换为日期

时间:2011-05-13 13:31:08

标签: iphone objective-c ios nsdateformatter

HI,我有一个字符串2011-05-13T00:00:00我想以MMM d,yyyy格式转换此字符串。 任何帮助?

4 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

阅读本文: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1

我不在我的Mac上,但这应该让你先行一步:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'"];
NSDate *originalDate = [dateFormatter dateFromString:originalDateString];
[dateFormatter setDateFormat:@"MM' 'DD','yyyy"];
NSString *formattedDateString = [dateFormatter stringFromDate:originalDate];
[dateFormatter release];

答案 2 :(得分:0)

使用此代码

NSDateFormatter * df = [[NSDateFormatter alloc] init];

[df setDateFormat:@“yyyy-MM-dd hh:mm:ss a”];

NSDate * myDate = [df dateFromString:myDateAsAStringValue];

答案 3 :(得分:0)

onResponse