Iphone ios-今天上午10点开始

Iphone ios-今天上午10点开始,iphone,ios,nsdate,Iphone,Ios,Nsdate,如何在ios中获得今天上午10点和明天上午10点 NSDateComponents *nowComponents = [calendar components:NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:today]; [每小时10分钟]; 这并没有给出正确的回应。我如何才能做到这一点?试试这段代码,希望它能

如何在ios中获得今天上午10点和明天上午10点

NSDateComponents *nowComponents = [calendar components:NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:today];
[每小时10分钟];


这并没有给出正确的回应。我如何才能做到这一点?

试试这段代码,希望它能起作用。如果您想获得明天上午10点的
hour,请将hour设置为
34

NSDate *date = [NSDate date];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
[gregorian setTimeZone:gmt];
NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];
[components setHour: 10];
[components setMinute:0];
[components setSecond: 0];
NSDate *newDate = [gregorian dateFromComponents: components];
NSLog(@"Date%@", newDate);
[gregorian release];