Convert string to NSDate with custom format

Possible duplicate:
NSString for NSDate
iPhone: how to convert a string of format "yyyyMMddThhmmss" to NSDate?

How to convert this format to NSDate?

My string date format is: yyyy-m-d'T'H:m:ss (no spaces between intervals).

Update:

 2012-11-06T12:17:22.947 would be the string that I'd like to convert to NSDate 
+1
source share
1 answer

just paste this method into your .m file and then call this method with your stringDate ..

 -(NSDate *)convertStringToDate:(NSString *) date { NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; NSDate *nowDate = [[[NSDate alloc] init] autorelease]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"]; date = [date stringByReplacingOccurrencesOfString:@"+0000" withString:@""]; nowDate = [formatter dateFromString:date]; // NSLog(@"date============================>>>>>>>>>>>>>>> : %@", nowDate); return nowDate; } 
+6
source

All Articles