objective c - Convert NSDate to other format -


possible duplicate:
nsdateformatter , yyyy-mm-dd

i have nsdate variable in format yyyy-mm-dd want convert dd/mm/yyyy. how can it?

nsdateformatter *f = [[nsdateformatter alloc] init]; [f setdateformat:@"yyyy-mm-dd"];             nsdate *date = [f datefromstring:[[jugador objectatindex:0] valueforkey:@"fecha_nac"]]; 

thanks

using same nsdateformatter u can format date using setdateformat , retreive date using datefromstring

for example :

nsdateformatter *dateformat1 = [[nsdateformatter alloc] init];  [dateformat1 setdateformat:@"yyyy-mm-dd"];  nsstring *strtoday = [dateformat1  stringfromdate:[nsdate date]];// string yyyy-mm-dd format  [dateformat1 setdateformat:@"dd/mm/yyyy"];  nsdate *todaydate = [dateformat1 datefromstring:strtoday];// date dd/mm/yyyy format 

edit : changes in code of example


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 -