I have a time of NSString type. i wonder get the day, but i find somethine strange.
NSString *strTime = @"2010-05-14 16:00:01";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *oldDate = [formatter dateFromString:strTime];
unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponen开发者_如何学Pythonts* components = [calendar components:flags fromDate:oldDate];
int day = [components day];
When NSString *strTime = @"2010-05-14 16:00:01" the day is 15,and when NSString *strTime = @"2010-05-14 16:00:00" the day is 14.I want to know why?
You are in California (probably) and the date object is GMT. Using the NSCalendar means that the date will be converted from your locale to GMT.
精彩评论