iOS 时间 解析

解决获取当前时间问题:

1.因为获取的当前时间和实际时间差8个小时

2.获取当前日期并格式化的时候比实际时间多一天

NSDate *date = [NSDate date];

NSTimeZone *zone = [NSTimeZone systemTimeZone];

NSInteger interval = [zone secondsFromGMTForDate: date];

NSDate *localeDate = [date  dateByAddingTimeInterval: interval];

NSLog(@"enddate=%@",localeDate);

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"];

[formatter setTimeZone:timeZone];

[formatter setDateStyle:kCFDateFormatterLongStyle];

[formatter setTimeStyle:kCFDateFormatterLongStyle];

[formatter setDateFormat:@"YYYY-MM-dd"];

NSLog(@"dd=%@",[formatter stringFromDate:localeDate]);

你可能感兴趣的:(iOS 时间 解析)