0
我想比较当前时间10:15的时间,然后找到差异即。时间为10点15分。一切编译,但我总是得到75 ....有人可以帮忙吗?如果可能,我会非常喜欢编码示例。此外,我试图使用 - (时间间隔)timeIntervalSinceNow,但我无法弄清楚如何工作,所以如果任何人也有这样的解释,我会非常感谢 *注意我使用的是版本3.2.6,请指教因此,谢谢如何正确找到此代码中的时差?
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components =
[gregorian components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:today];
NSInteger hour = [components hour];
NSInteger minute = [components minute];
NSInteger second = [components second];
NSInteger combo = hour + (minute/60) + (second/3600);
NSTimeInterval time = combo*60*60;
NSTimeInterval tenFifteenFirstPeriodStop = 10.25*60*60;
double myDouble;
int myInt;
NSString* myNewString;
NSString *info;
if(time <tenFifteenFirstPeriodStop){
myDouble = (tenFifteenFirstPeriodStop-time)/60;
myInt = (int)(myDouble + (myDouble>0 ? 0.5 : -0.5));
myNewString = [NSString stringWithFormat:@"%d", myInt];
info = [[NSString alloc] initWithFormat:
@"%@",myNewString];
}
NSString *message = [[NSString alloc] initWithFormat:
@"%@", info];
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Minutes Until the Bell Rings" message:message delegate:nil cancelButtonTitle:@"Great!" otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
请尝试格式化您的代码 - 它现在看起来几乎不可读。 – 2011-06-15 15:34:32