ios - change date format in iPhone -


i trying since last 2 hours , finaly left out guys :p

i need convert string mon, 14 may 2012, 12:00:55 +0200 date dd/mm/yyyy hh:ss format..

any kind of towards goal appreciated.

what have tried

i have tried using nsdateformatter unable figure out exact format of above date. [dateformatter setdateformat:@"eeeddmm,yyyy hh:mm:ss"]; how have tried , many other formats too

eg:

 nsstring *finaldate = @"tue, 29 may 2012, 14:24:56 +0200";  nsdateformatter *dateformatter = [[nsdateformatter alloc] init];  [dateformatter setdateformat:@"eeeddmm,yyyy hh:mm:ss"];   nsdate *date = [dateformatter datefromstring:finaldate]; 

here date alwasys comes nil

the important part of date formatting forgotten, tell nsdateformatter input language:

nsdateformatter *dateformatter = [nsdateformatter new]; [dateformatter  setdateformat:@"eee, dd mmmm yyyy, hh:mm:ss z"]; dateformatter.locale = [[nslocale alloc] initwithlocaleidentifier:@"en"]; nsdate *date = [dateformatter datefromstring:@"mon, 14 may 2012, 12:00:55 +0200"]; nslog(@"date: %@", date); 

i've checked output: date: 2012-05-14 10:00:55 +0000

be aware hh in date formatter 24hr.

now suggest not use fixed output scheme, use 1 of nsdateformatterstyle:

[dateformatter setdatestyle:nsdateformattershortstyle]; [dateformatter settimestyle:nsdateformattershortstyle];  nsstring *datestring = [dateformatter stringfromdate:date];  nslog(@"date: %@", datestring); 

which in american english output: 5/14/12 12:00 pm


this code valid arc if not using arc add autorelease nslocale , release nsdateformatter after done it.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -