I have the need of getting NSDate format from a NSString *stringDate and I would do that by using the following code:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSDate *date = [formatter dateFromString:stringDate];
The above code works fine if I initialize my string manually NSString *stringDate = @"2013-01-14 17:55:53";, so I get the date in NSDate format correct.
But I am reading the string from an sqlite3 database, so the string is initialized as follows:
NSString *stringDate = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)];
The string is NSLogged correctly, but when I try to get the NSDate format i get only (null).
Any ideas of what could be the problem? Thanks!
The string you read from the sqlite is not in the format that you are using in dateformatter.
EDIT:
Use
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss z";or trimming time zone(+0000)will solve your problem.-By Inder Kr. Rathore