objective c - NSDate returning nil in iOS -


this question has answer here:

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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -