MySQL 'timestamp' string to NSDate
Quick and easy tutorial to show you how you can convert the MySQL 'timestamp' data type as a string to an NSDate variable.
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];
Written by Max Kramer
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mysql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#