Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa: int as string w/format

Cocoa: int as string w/format
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 29, 2002, 05:59 PM
 
Hi,

This should be really easy for someone:

I have to integers hours and minutes, I want to display them like this: 01:40 as a string

or like this if the hours int was 2 and the minutes was 5, 02:05

Is there any easy way to do this, I found the stringByAppendingString method but then I have to check to see if minutes <10 or hours<10 to put a zero before hand.

Is there some sort of easy formatter?

Thanks.
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Oct 29, 2002, 06:54 PM
 
I Believe this does the trick:

int hours = 5;
int minutes = 9;
int seconds = 6;

NSString *time = [NSString stringWithFormat:@"%d hours, %.2d minutes, and %.2d seconds",hours,minutes,seconds];

//@"5 minutes, 09 minutes, 06 seconds"

HTH,
Matt
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 29, 2002, 07:10 PM
 
Thanks that is the tip I needed!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:16 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2