Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i find the time difference in this code correctly?
    primarykey
    data
    text
    <p>I am trying to compare the current time to the time 10:15 and then find the difference ie. the minutes left until 10:15. Everything compiles, but I always get 75....Can someone help?? I would really love coding examples if at all possible. Also I tried to use -(time interval)timeIntervalSinceNow, but I couldnt figure out how to work it, so if anyone has an explanation for that too, i would be extremely grateful *Note i am using Version 3.2.6, please advise accordingly, thanks</p> <pre><code>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 &lt;tenFifteenFirstPeriodStop){ myDouble = (tenFifteenFirstPeriodStop-time)/60; myInt = (int)(myDouble + (myDouble&gt;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]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload