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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 05-27-2011, 08:16 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 82
shahab74 is on a distinguished road
Default Format time by minutes

I have a NSTimer which displays the time as "00.00.00" by using the following code :

Code:
- (void)showTime{
    
    startTime++;
    
    int secs = startTime % 60;
    int mins = (startTime / 60) % 60;
    int hour = (startTime / 3600);
    
    
    lblRaceTime.text = [NSString stringWithFormat:@"%.2d:%.2d:%.2d",hour, mins, secs];
    
}
so if the value is displayed as "00.01.15" how can I just show 1.15 mins? and if value of the lblRaceTime is "01.10.15"(very unlikely) then show 1 hr and 10 mins. Please any advice or directions will be greatly appreciated

Last edited by shahab74; 05-27-2011 at 08:21 AM.
shahab74 is offline   Reply With Quote
Old 05-27-2011, 08:17 AM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 140
MatthewD is on a distinguished road
Default

If hours is equivalent to 0, do not display hours.
MatthewD is offline   Reply With Quote
Old 05-27-2011, 08:24 AM   #3 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Code:
- (void)showTime{
    
    startTime++;
    
    int secs = startTime % 60;
    int mins = (startTime / 60) % 60;
    int hour = (startTime / 3600);
    
    NSString *stringLabel0 = [NSString stringWithFormat:@"%.2d",secs];
    NSString *stringLabel1 = @"";
    NSString *stringLabel2 = @"";

    if(mins>0 || hour>0)
         stringLabel1 = [NSString stringWithFormat:@"%.2d:",mins];

    if(hour>0)
         stringLabel2 = [NSString stringWithFormat:@"%.2d:",hour];

    lblRaceTime.text = [NSString stringWithFormat:@"%@%@%@",stringLabel2, stringLabel1, stringLabel0];
    
}
__________________

Last edited by dany_dev; 05-27-2011 at 08:34 AM.
dany_dev is offline   Reply With Quote
Old 05-27-2011, 08:31 AM   #4 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 82
shahab74 is on a distinguished road
Default

Champion stuff!! Thanks heaps, much appreciated!!
shahab74 is offline   Reply With Quote
Reply

Bookmarks

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: 339
6 members and 333 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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