Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
- Subject: Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
- From: Graham Cox <email@hidden>
- Date: Thu, 11 Dec 2008 11:15:56 +1100
On 11 Dec 2008, at 11:03 am, Chunk 1978 wrote:
i believe i painted myself into a corner here... i have a
NSPopUpButton with 3 items. 1 Hour, 2 Hours, 3 Hours. each item has
respected tag numbers 1, 2 and 3. i'm attempting to print out time
remaining but i can only get as far as displaying seconds remaining
with this: NSLog(@"%.2d Seconds Remaining", (hoursSelected -
second)); but i would like for the log to output @"%.2d Hours, %.2d
Minutes and - Seconds Remaining"; i can't wrap my head around it,
and i fear that my trying to be as if/else statementless as possible
by using the tag numbers of the PopUp Menu is causing me problems.
warning: typed into mail, off the top of my head:
int hours, minutes, seconds, totalSecondsRemaining;
totalSecondsRemaining = ( menuValue * 3600 ) - timeElapsedSoFar;
hours = totalSecondsRemaining % 3600;
totalSecondsRemaining -= ( hours * 3600 );
minutes = totalSecondsRemaining % 60;
totalSecondsRemaining -= ( minutes * 60 );
seconds = totalSecondsRemaining;
NSLog(@"remaining time: %.2d hours, %.2d minutes, %.2d seconds",
hours, minutes, seconds );
n.b the key is to use the mod operator (%). I believe in some schools
modulo arithmetic is called "clock arithmetic".
hth,
Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden