how to convert from NSString to NSDate ?
it must be in yyyy-MM-dd HH:mm:ss this format when it converts from NSString to NSDate format
Use NSDateFormatter's dateFromString:
NSString *dateStr = @"20100212";
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *date = [dateFormat dateFromString:dateStr];
// Convert date object to desired output format
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
dateStr = [dateFormat stringFromDate:date];
[dateFormat release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With