• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Countdown With NSTimer - Hours, Minutes, Seconds Remaining? (From: "Chunk 1978" <email@hidden>)

  • Prev by Date: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
  • Next by Date: Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
  • Previous by thread: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
  • Next by thread: Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
  • Index(es):
    • Date
    • Thread