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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:55:07+00:00 2026-06-13T11:55:07+00:00

I use NSTimer to count from a certain moment. int totalSeconds; int totalMinutes; int

  • 0

I use NSTimer to count from a certain moment.

int totalSeconds;
int totalMinutes;
int totalHours;

If the totalSeconds are 60, totalMinuts become +1. Its very simple and should work.
For example i started the NSTimer together with the clock of my mac. (running on simulator).
When i look at the clock of my mac and the timer and compare the time the first 10-20 seconds its counting perfectly synchronous. After that it fluctuates or goes ahead 5 seconds or more.
So i output my timer and found this:

  • 2012-10-24 14:45:44.002 xxApp driveTime: 0:0:44
  • 2012-10-24 14:45:45.002 xxApp driveTime: 0:0:45
  • 2012-10-24 14:45:45.813 xxApp driveTime: 0:0:46
  • 2012-10-24 14:45:46.002 xxApp driveTime: 0:0:47

The milliseconds are timed at 002 as you see. But at the third row its 813. This happens very randomly and causes the fluctuations.

Is there a more stable way to count?

  • 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-06-13T11:55:08+00:00Added an answer on June 13, 2026 at 11:55 am

    From the NSTimer documentation

    A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds.

    If your goal is to compute the total time that has passed since your program has started running, this is quite easy. As soon as you want to begin keeping track of time, store -[NSDate date] into a variable. Whenever you want to compute how much time has passed, call -[NSDate date again and do the following, assuming originalDate is a property where you stored the result of the first call to -[NSDate date]:

    NSDate *presentDate = [NSDate date];
    NSTimeInterval runningTime = [presentDate timeIntervalSinceDate:originalDate];
    

    runningTime will be the total number of seconds that have elapsed since you started keeping track of time. In order to get the number of hours, minutes, seconds, and so on, an NSDateComponents object should be used.

    This mechanism will allow you to use a timer to update your total running time “just about once a second” without losing accuracy.

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

Sidebar

Related Questions

How can I use the NSTimer in Monotouch to count down from some number
Recently I use NSTimer to repeat taking photos, it'll show on the screen. This
I'm currently making a little game with a countdown timer. I use an NSTimer,
Use of gradient images is very common among developers for styling a page. Gradient
I'm trying to learn how to use NSTimer s, and I thought of the
I use a NSTimer which fires every second and updates a label which displays
Possible Duplicate: How do I use NSTimer Decrement Issue I'm really struggling to get
Possible Duplicate: How do I use NSTimer I'd like to create a timer: When
I am trying to use an NSTimer to call a method, but it doesn`t
I want to use NSTimer to call a method once the view is done

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.