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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:10:30+00:00 2026-06-14T18:10:30+00:00

I have a NSTimer and an NSDate working together to make a countdown clock.

  • 0

I have a NSTimer and an NSDate working together to make a countdown clock. A UILabel is then updated with the countdown.

The problem I’m facing is that the countdown clock works in the simulator but doesn’t on the device. The simulator iOS 6.0 and the device iOS 6.0.1.

here’s my code:

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];

    [self startTimer];

}

 // timer and update label to display a countdown clock 
- (void)startTimer {

    // Create a timer that fires every second repeatedly and save it in an ivar
    NSTimer *timer = [[NSTimer alloc] init];

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];

}

  - (void)updateLabel {

    // convert date string to date then set to a label
    NSDateFormatter *dateStringParser = [[NSDateFormatter alloc] init];
    [dateStringParser setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.000Z"];

    NSDate *date = [dateStringParser dateFromString:deadlineDate];

    NSLog(@"date from update label %@", date);

    NSTimeInterval timeInterval = [date timeIntervalSinceNow]; ///< Assuming this is in the future for now.

    NSString *stringVariable = [self stringFromTimeInterval:timeInterval];

    self.deadlineLbl.text = [NSString stringWithFormat:@"%@", stringVariable];

    NSLog(@"%@",stringVariable);

}

- (NSString *)stringFromTimeInterval:(NSTimeInterval)interval {
    NSInteger ti = (NSInteger)interval;
  //  NSInteger seconds = ti % 60;
    NSInteger minutes = (ti / 60) % 60;
    NSInteger hours = (ti / 3600);
    return [NSString stringWithFormat:@"%02i hours : %02i min", hours, minutes];
}

here’s some console output first on the simulator and then on the device:

simulator console output:

2012-11-14 15:39:57.021 appName[7856:13d03] 31 hours : 20 min
2012-11-14 15:39:58.020 appName[7856:13d03] 31 hours : 20 min
2012-11-14 15:39:59.021 appName[7856:13d03] 31 hours : 19 min
2012-11-14 15:40:00.021 appName[7856:13d03] 31 hours : 19 min

device console output:

2012-11-14 15:45:44.887 appName[7556:907] 00 hours : 00 min
2012-11-14 15:45:45.896 appName[7556:907] 00 hours : 00 min
2012-11-14 15:45:46.891 appName[7556:907] 00 hours : 00 min
2012-11-14 15:45:47.891 appName[7556:907] 00 hours : 00 min

another problem I’m having is that the timer keeps updating after the user leaves the view.

thanks for any help

  • 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-14T18:10:31+00:00Added an answer on June 14, 2026 at 6:10 pm

    Check for date variable in line:

    NSDate *date = [dateStringParser dateFromString:deadlineDate];
    

    Check in debugger if the date is not nil. If it is, then the problem is in the deadlineDate which is not in expected format defined in dateStringParser (or deadlineDate is nil as well).

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

Sidebar

Related Questions

I have an NSTimer running in my application that collects some data and sends
I have created an app that uses NSTimer, which gets triggered each second. My
I need to start NSTimer by 0:0:0 that I am doing and I have
I have implemented a simple clock like so: - (void)runTimer { timer = [NSTimer
I have written the code shown below. my problem is that I can't touch
I have an NSTimer that I initialize with scheduledTimerWithTimeInterval: with a very short interval
I have my NSTimer embedded in a class that plays image sequences. Basically it
I have created a NSTimer In Xcode 4.2 and it works but i get
I have an NSTimer that fires off every second, and on that second I
I have a NSTimer that fires with an interval of 3 seconds to decrease

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.