获取当天凌晨的时间

NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];

[calendar setTimeZone:gmt];

NSDate *date = [NSDate date];

NSDateComponents *components = [calendar components:NSUIntegerMax fromDate:date];

components.day-=1;

[components setHour:0];

[components setMinute:0];

[components setSecond: 0];

NSDate *startDate = [calendar dateFromComponents:components];

NSDate *endDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:startDate options:0];
NSLog(@"%@", endDate);

你可能感兴趣的:(获取当天凌晨的时间)