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 1005463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:17:59+00:00 2026-05-16T08:17:59+00:00

I am trying to make a stop watch with NSTimer. I gave the following

  • 0

I am trying to make a stop watch with NSTimer.

I gave the following code:

 nst_Timer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(showTime) userInfo:nil repeats:NO];

and it is not working in milliseconds. It takes more than 1 millisecond.

  • 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-16T08:18:00+00:00Added an answer on May 16, 2026 at 8:18 am

    Don’t use NSTimer that way. NSTimer is normally used to fire a selector at some time interval. It isn’t high precision and isn’t suited to what you want to do.

    What you want is a High resolution timer class (using NSDate):

    Output:

    Total time was: 0.002027 milliseconds
    Total time was: 0.000002 seconds
    Total time was: 0.000000 minutes
    

    Main:

    Timer *timer = [[Timer alloc] init];
    
    [timer startTimer];
    // Do some work
    [timer stopTimer];
    
    NSLog(@"Total time was: %lf milliseconds", [timer timeElapsedInMilliseconds]);  
    NSLog(@"Total time was: %lf seconds", [timer timeElapsedInSeconds]);
    NSLog(@"Total time was: %lf minutes", [timer timeElapsedInMinutes]);
    

    Edit: Added methods for -timeElapsedInMilliseconds and -timeElapsedInMinutes

    Timer.h:

    #import <Foundation/Foundation.h>
    
    @interface Timer : NSObject {
        NSDate *start;
        NSDate *end;
    }
    
    - (void) startTimer;
    - (void) stopTimer;
    - (double) timeElapsedInSeconds;
    - (double) timeElapsedInMilliseconds;
    - (double) timeElapsedInMinutes;
    
    @end
    

    Timer.m

    #import "Timer.h"
    
    @implementation Timer
    
    - (id) init {
        self = [super init];
        if (self != nil) {
            start = nil;
            end = nil;
        }
        return self;
    }
    
    - (void) startTimer {
        start = [NSDate date];
    }
    
    - (void) stopTimer {
        end = [NSDate date];
    }
    
    - (double) timeElapsedInSeconds {
        return [end timeIntervalSinceDate:start];
    }
    
    - (double) timeElapsedInMilliseconds {
        return [self timeElapsedInSeconds] * 1000.0f;
    }
    
    - (double) timeElapsedInMinutes {
        return [self timeElapsedInSeconds] / 60.0f;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a stop watch application that when you press start
I am trying to make it stop showing the rest if $walk_jail is not
Trying to make an xna game, where the user needs to tap to stop
I've been trying to make this script from ClearBox3 to stop conflicting with MooTools
I have been trying to make an init script using start-stop-daemon. I am stuck
Please stop me before I make a big mistake :) - I'm trying to
Does anyone know how to make this code stop the knob from rotating past
now I'm trying to make the keyboard events to stop repeating. My idea was
Im trying to make some text non-copyable, my aim isn't to stop people from
I am trying to make a stop button for this loop but it runs

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.