How to convert the Date String "2012-05-03 06:03:00 +0000" to NSDate. I user the code below, but it does not work:
NSDateFormatter *datFormatter = [[NSDateFormatter alloc] init];
[datFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSDate* date = [datFormatter dateFromString:dateStr];
NSString *dateStr = @"2012-05-03 06:03:00 +0000";
NSDateFormatter *datFormatter = [[NSDateFormatter alloc] init];
[datFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSDate* date = [datFormatter dateFromString:dateStr];
NSLog(@"date: %@", [datFormatter stringFromDate:date]);
This code prints date: 2012-05-03 09:03:00 +0300
It works. Also don't forget to set the date formatter's timeZone that you're targeting
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