ios - Convert NSString with format Tue, 27 Aug 2013 22:22:04 EDT to NSDate -
i trying convert nsstring
following format: tue, 27 aug 2013 22:22:04 edt
nsdate
getting nil
.
here's attempt
// pub date in string** nsstring *pubdate = @"tue, 27 aug 2013 22:22:04 edt"; nsarray *temparr =[ pubdate componentsseparatedbystring:@" "]; nsmutablearray *temparrfinal = [nsmutablearray arraywitharray:temparr]; [temparrfinal removelastobject]; [temparrfinal removeobjectatindex:0]; pubdate = [temparrfinal componentsjoinedbystring:@" "];
here before passing date formatter converted nsstring
format this: 27 aug 2013 22:22:04
removing first n last component of string. i've done because original format getting same result.
this how trying o convert nsdate
:
nsdateformatter *formatter = [[[nsdateformatter alloc] init] autorelease]; [formatter setdateformat:@"mmm dd yyyy hh:mm:ss"]; [formatter setdatestyle:nsdateformatterlongstyle]; articledate = [formatter datefromstring:pubdate];
you have set nsdateformatter according date format
try this, if using type of date 27 aug 2013 22:22:04
nsstring *string=@"27 aug 2013 22:22:04"; nsdateformatter *df=[[nsdateformatter alloc]init]; [df setdateformat:@"dd mmm yyyy hh:mm:ss"]; nsdate *date=[df datefromstring:string];
or if using tue, 27 aug 2013 22:22:04 edt
type of date try this
nsstring *string=@"tue, 27 aug 2013 22:22:04 edt"; nsdateformatter *df=[[nsdateformatter alloc]init]; [df setdateformat:@"e, dd mmm yyyy hh:mm:ss zz"]; nsdate *date=[df datefromstring:string];
Comments
Post a Comment