i want to convert the string into nsdate format.
here is my string NSString str=@”Sunday, June 6, 2010 5:00:00 AM CDT”;
my code is
NSDateFormatter * Dateformats= [[NSDateFormatter alloc] init];
[Dateformats setDateFormat:@"MM/DD/yyyy hh:mm:ss"]; //ex @"MM/DD/yyyy hh:mm:ss"
NSDate *myDate=[Dateformats dateFromString:str];
NSLog(@"%@",myDate);
but it is displays null so show me the way to display the date in MM/DD/yyyy hh:mm:ss
please friends help me ,how to do this
You set your formatter to expecting a string like
@"05/26/2012 8:34:00". But you give it@"Sunday, June 6, 2010 5:00:00 AM CDT". The two formats are nothing alike. It doesn’t know how to parse it and so returnsnil.The format you want for the example string you give is
EEEE, MMMM d, yyyy h:mm:ss a zzz.Details here and here.