String ‘timestamp’ do MySQL para NSDate

Tutorial rápido e fácil para mostrar como você pode converter o tipo de dados ‘timestamp’ do MySQL como uma string para uma variável NSDate.

NSString *dateAsString = [self.userInfo objectForKey:@"last_updated"];

/* @dateAsString is the MySQL timestamp as a string */

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

/* the date format is the same as that used by MySQL timestamps */

NSDate *date = [formatter dateFromString:dateAsString];

/* as if by magic, the date is returned into the 'date' variable */

[formatter release];