Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nekbeth

macrumors regular
Original poster
Feb 20, 2011
101
0
Vatican City
Hello, I'm trying to get the Total minutes for a Timer. I already got the seconds working. Here is how I got "Total Seconds":

Code:
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];



    NSDateComponents *comps = [gregorian components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:time];



    NSInteger hour = [comps hour];

    NSInteger minute = [comps minute];

    NSLog(@"Hour:%i", hour);

    NSLog(@"minute:%i", minute);

    NSInteger secs =hour * 60 * 60 + minute * 60;





    NSNumber *elapsedSeconds = [[NSNumber alloc] initWithInt:secs];

    NSDictionary *myDict = [NSDictionary dictionaryWithObject:elapsedSeconds forKey:@"TotalSeconds"];



It might be only to change the formula, any help would be much appreciated. Thanks
 
This may be massively simplistic but if you know the total elapsed seconds what is preventing you dividing that by 60 to get the number of minutes?
 
You mean, something like :


Code:
 NSInteger mins = secs / 60;
 NSNumber *elapsedMinutes = [[NSNumber alloc] initWithInt:mins];


  NSDictionary *myMin = [NSDictionary dictionaryWithObject:elapsedMinutes forKey:@"TotalMinutes"];
??
 
:) , is robbie ok ? * while you see this message, do you know how to make "Total Second" to reach 60 and loop again, instead of showing me "456 seconds remaing". *Minutes change if I set the scheduletime for 60, but only show up in my log until the first minute has passed. *

(I'm using a date picker)

Thanks
 
:) , is robbie ok ?

Yes :)

* while you see this message, do you know how to make "Total Second" to reach 60 and loop again, instead of showing me "456 seconds remaing". *Minutes change if I set the scheduletime for 60, but only show up in my log until the first minute has passed. *

(I'm using a date picker)
Thanks

Look at the modulus operator (%). For example 456 % 60 is 36.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.