Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-23-2009, 10:24 PM   #1 (permalink)
Registered Member
 
Eagle11's Avatar
 
Join Date: Aug 2009
Age: 20
Posts: 192
Default Formatting Strings question

I have a question about formatting a string. I have a timer in my app that displays hour:min:sec. Right now I am using this line:

Code:
NSString *nssTimer = [NSString stringWithFormat:@"%2i:%2i:%2i", nsiTimerHour, nsiTimerMin, nsiTimerSeconds];
to format the string. The problem is that is ends of looking like this
#: #: #
when the numbers are less than ten. I want it to look like this
##:##:##
regardless of what the values are.
Is there a way to achieve that?
Eagle11 is offline   Reply With Quote
Old 08-24-2009, 01:26 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: currently AZ
Posts: 112
Send a message via MSN to kingbombs
Default

you can just try
NSDate *newdate = alloc or what ever
then string with format %@
will print all of it for you, now will put the date in there but i think there is a way (think it says in apple docs) to just show the time

EDIT: about to go to bed so sorry for being brief
kingbombs is offline   Reply With Quote
Old 08-25-2009, 12:00 PM   #3 (permalink)
Objective-C Code Monkey
 
deansx's Avatar
 
Join Date: May 2009
Location: Mountain View, CA
Posts: 127
Default

Quote:
Originally Posted by Eagle11 View Post
I have a question about formatting a string. I have a timer in my app that displays hour:min:sec. Right now I am using this line:

Code:
NSString *nssTimer = [NSString stringWithFormat:@"%2i:%2i:%2i", nsiTimerHour, nsiTimerMin, nsiTimerSeconds];
to format the string. The problem is that is ends of looking like this
#: #: #
when the numbers are less than ten. I want it to look like this
##:##:##
regardless of what the values are.
Is there a way to achieve that?
I have some code that displays minutes:seconds:tenths. I want the minutes and seconds to be two digits, even if there are less than 10 of either. The formatting that works for me is:
Code:
[self setText:[NSString stringWithFormat:@"%02d:%02d.%1d",dispMins,dispSecs,tsecs]];
Will give output, of:

Quote:
02:08.3
for 2 minutes, 8 and 3 tenths seconds.

Good luck!
deansx is offline   Reply With Quote
Old 08-25-2009, 12:08 PM   #4 (permalink)
Registered Member
 
Eagle11's Avatar
 
Join Date: Aug 2009
Age: 20
Posts: 192
Default

Quote:
Originally Posted by deansx View Post
I have some code that displays minutes:seconds:tenths. I want the minutes and seconds to be two digits, even if there are less than 10 of either. The formatting that works for me is:
Code:
[self setText:[NSString stringWithFormat:@"%02d:%02d.%1d",dispMins,dispSecs,tsecs]];
Will give output, of:



for 2 minutes, 8 and 3 tenths seconds.

Good luck!
Thanks for the help!
Eagle11 is offline   Reply With Quote
Reply

Bookmarks

Tags
formatting, string, timer

Thread Tools
Display Modes

Posting 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



» Advertisements
» Online Users: 267
17 members and 250 guests
@sandris, ADY, Alsahir, dacapo, Dani77, Desert Diva, djohnson, HemiMG, jansan, JasonR, MarkC, mer10, prchn4christ, ryandb2, smethorst, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:58 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0