NSDate to NSString returns nil -
nsstring *datestring = @"13-8-06 10:53:54 +0300"; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; // imporant - set our input date format match our input string // if format doesn't match you'll nil string, careful [dateformatter setdateformat:@"yy-mm-dd hh:mm 'zz'"]; nsdate *datefromstring = [[nsdate alloc] init]; // voila! datefromstring = [dateformatter datefromstring:datestring];
datefromstring nil. know format should give nsdateformatter??
try
nsstring *datestring = @"13-8-06 10:53:54 +0300"; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat:@"dd-mm-yy hh:mm:ss zzz"]; nsdate *date =[dateformatter datefromstring:datestring]; nslog(@"%@",date); [dateformatter setdateformat:@"yyyy-mm-dd hh:mm:ss zzz"]; datestring =[dateformatter stringfromdate:date]; nslog(@"%@",datestring);
Comments
Post a Comment