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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -