Convert NSDate to other format

ios5, objective-c

Solution

Using same NSDateformatter u can format date using setDateFormat and retreive date using dateFromString

For example :

NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc] init];

[dateFormat1 setDateFormat:@"yyyy-MM-dd"];

NSString *strToday = [dateFormat1  stringFromDate:[NSDate date]];// string with yyyy-MM-dd format

[dateFormat1 setDateFormat:@"dd/MM/yyyy"];

NSDate *todaydate = [dateFormat1 dateFromString:strToday];// date with dd/MM/yyyy format

EDIT : changes in code of `example`

Problem

Possible Duplicate: NSDateFormatter and yyyy-MM-dd I have an NSDate variable in format yyyy-MM-dd that I want to convert to dd/MM/yyyy. How can I do it? ``` NSDateFormatter *f = [[NSDateFormatter alloc] init]; [f setDateFormat:@"yyyy-MM-dd"]; NSDate *date = [f dateFromString:[[jugador objectAtIndex:0] valueForKey:@"FECHA_NAC"]]; ``` Thanks

Original source

Related problems