Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:39:33+00:00 2026-05-30T06:39:33+00:00

How can I change this code so it has HH:MM:SS (hours, minutes, seconds)? Do

  • 0

How can I change this code so it has HH:MM:SS (hours, minutes, seconds)?

Do I need to add code in .h or .m so I known which one?

At the moment it goes up like 1, 2, 3, 4 etc.

Just to let you known I’m bait of a amateur would you copy and past so I known what you mean.

.h

@interface FirstViewController : UIViewController {
    
    IBOutlet UILabel *time; 
    
    NSTimer *myticker;
    
    //declare baseDate
    NSDate* baseDate; 

}

-(IBAction)stop;
-(IBAction)reset;

@end

.m

#import "FirstViewController.h"

@implementation FirstViewController

-(IBAction)start {
    [myticker invalidate];
    baseDate = [NSDate date];
    myticker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
}

-(IBAction)stop;{ 
    
    [myticker invalidate];
    myticker = nil;
}
-(IBAction)reset;{
    
    time.text = @"00:00:00";
}
-(void)showActivity {
    NSTimeInterval interval = [baseDate timeIntervalSinceNow];
    NSUInteger seconds = ABS((int)interval);
    NSUInteger minutes = seconds/60;
    NSUInteger hours = minutes/60;
    time.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes%60, seconds%60];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:39:35+00:00Added an answer on May 30, 2026 at 6:39 am

    First, declare baseDate variable in your FirstViewController.h, like this:

    @interface FirstViewController : UIViewController {
    
        IBOutlet UILabel *time; 
    
        NSTimer *myticker;
    
        //declare baseDate
        NSDate* baseDate;
    }
    

    Then, in the FirstViewController.m start method add baseDate = [NSDate date] like this:

    -(IBAction)start {
        [myticker invalidate];
        baseDate = [NSDate date];
        myticker = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
    }
    

    After that, change your showActivity method to look like this:

    -(void)showActivity {
        NSTimeInterval interval = [baseDate timeIntervalSinceNow];
        double intpart;
        double fractional = modf(interval, &intpart);
        NSUInteger hundredth = ABS((int)(fractional*100));
        NSUInteger seconds = ABS((int)interval);
        NSUInteger minutes = seconds/60;
        NSUInteger hours = minutes/60;
        time.text = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d", hours, minutes%60, seconds%60, hundredth];
    }
    

    Also note, that you will have to change the interval value for your timer, otherwise your label will only be updated once a second.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from this code will show in original color how can i change it to
How can I change the master volume level? Using this code [DllImport (winmm.dll)] public
I have a corollary question to This one. How can you change the spacing
I can set data in JTable constructor, and then user can change this data
(r'^/(?P<the_param>[a-zA-z0-9_-]+)/$','myproject.myapp.views.myview'), How can I change this so that the_param accepts a URL(encoded) as a
You can change the connection string at run-time like this. You make the connection
According to this website , you can change to command key sequence used by
Can't work this out... I've got a .change event handler for multiple select boxes.
Can someone tell me how to change directories using FtpWebRequest? This seems like it
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.