开发者

NSString long date format to NSDate

I have a string in the form of

"11:00AM, Saturday 开发者_开发百科August 21, 2010"

How do I convert this to an NSDate object?


This should work:

NSString *input = @"11:00AM, Saturday August 21, 2010";
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateFormat:@"hh:mma, EEEE MMMM d, yyyy"];
NSDateFormatter *df2 = [[[NSDateFormatter alloc] init] autorelease];
[df2 setDateFormat:@"MMMM yyyy"];
NSDate *date = [df2 stringFromDate:[df dateFromString:input]];


And format your date object as you want.
http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns


Use a NSDateFormatter for this format. -(NSDate *)dateFromString:(NSString *)string is the method you want to use then.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜