NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *startDate = [dateFormatter dateFromString:@"2012-02-18 00:00:00"];
NSLog(@"%@", startDate);
The result is :
2012-02-17 16:00:00 +0000
We can see the time is not correct since the default timezone of NSDate is GMT +000(London), we must get the systemTimeZone and add interval to the date:
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:startDate];
startDate = [startDate addTimeInterval:interval];
NSLog(@"%@", startDate);
The result is :
2012-02-18 00:00:00 +0000
Read more of this post
You must be logged in to post a comment.