|
|
#1 |
|
Why can't convert NSString to NSDate?
I have a string is @"Tuesday, January 01, 2013", and I use code as below to convert it to date, but I only get nil, does anyone tell me why?
Code:
+ (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)format {
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:format];
NSDate *date = [inputFormatter dateFromString:string];
return date;
}
NSString *str = @"Tuesday, January 01, 2013";
NSDate *date = [NSDate dateFromString:str withFormat:@"EEEE, MMMM dd, yyyy"];
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
|
|
|
0
|
|
|
#2 | |
|
Quote:
|
||
|
|
0
|
|
|
#3 | |
|
Quote:
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
||
|
|
0
|
|
|
#4 |
|
Where is your class method declared? Have you added a category for NSDate?
Edit: my prior edit was incorrect. But have a look here, the author has an example of what you want near the bottom: http://www.cocoawithlove.com/2009/05...g-and.html?m=1 Last edited by dejo; Jan 22, 2013 at 10:37 AM. Reason: Fixed link. |
|
|
|
0
|
|
|
#5 |
|
Sure, I put that method in category NSDate+Helper
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 07:07 AM.







Linear Mode
