Because the timezone is different. NSDataDetector
use the GTM
, but your system timezone is not (I guess...).
I have a test like you , and it output like this :
So , you can use NSDateFormatter
the NSDateFormatter
's default timezone is the same as the system timezone , so you can get the right date.
NSString *lastRefreshStampString = @"2014-05-05 02:54:45 +0000";
NSLog(@"lastRefString:%@",lastRefreshStampString);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSLog(@"time zone : %@",dateFormatter.timeZone.name);
NSLog(@"system time zone : %@",[NSTimeZone systemTimeZone].name);
NSDate *lastRefreshStamp = [dateFormatter dateFromString:lastRefreshStampString];
NSLog(@"lastRef:%@",lastRefreshStamp);
The output is right :