objective c - NSDate returning nil in iOS -
this question has answer here:
- convert nsdate nsstring 12 answers
i trying set nsdate
string. format of string looks (rfc 2822):
tue, 09 jun 2015 06:09:38 +0000
the code using is:
nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; dateformatter.locale = [[nslocale alloc] initwithlocaleidentifier: @"en_us_posix"]; dateformatter.dateformat = @"eee, dd mmm yyyy hh:mm:ss z"; nsdate *datestring = [dateformatter datefromstring:self.time];
but datestring
returns nil. self.time
contains string time.
i think self.time either nil or in other format. check code put string manually , see result
nsstring *str = @"tue, 09 jun 2015 06:09:38 +0000"; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; dateformatter.locale = [[nslocale alloc] initwithlocaleidentifier: @"en_us_posix"]; dateformatter.dateformat = @"eee, dd mmm yyyy hh:mm:ss z"; nsdate *datestring = [dateformatter datefromstring:str]; nslog(@"date : %@",datestring);
i added sample gave me correct result. try once debug value of self.time
Comments
Post a Comment