开发者

NSString long date format to NSDate

开发者 https://www.devze.com 2023-01-12 03:00 出处:网络
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:

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

精彩评论

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