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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:13:09+00:00 2026-05-25T01:13:09+00:00

I need the iPhone to recognize the current time (which I can do fine

  • 0

I need the iPhone to recognize the current time (which I can do fine with NSDate) and have it countdown to the next time interval, say every half hour on the half hour. Example: if the current time is 2:12:30 and the interval is every half hour, I want a countdown to start at 17:30 (17 min 30 seconds left) and go to 0.

Code welcome, but also general program design thoughts welcome too. Here’s the code I have for starting a countdown and getting the current time:

-(void)updateCounter:(NSTimer *)theTimer {
        if(secondsLeft > 0 ){
            secondsLeft -- ;
            minutes = (secondsLeft % 3600) / 60;
            seconds = (secondsLeft % 3600) % 60;
            waitingTimeLabel.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
        }
        else{
            secondsLeft = 10;
        }
    }

    -(void)countdownTimer{
        //secondsLeft = minutes = seconds = 0;
        if([timer isValid])
        {
            [timer release];
        }
       // NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
        timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
        //[pool release];
    }
    -(NSDate *)getCurrentTime
    {
        NSDate *now = [NSDate date];

        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        dateFormatter.dateFormat = @"mm:ss";

        [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
        NSLog(@"The Current Time is %@",[dateFormatter stringFromDate:now]);
        //[dateFormatter release];
        NSString *currentTime = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:now]];
        currentTimeLabel.text = currentTime;
        return now;
    }
  • 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-25T01:13:10+00:00Added an answer on May 25, 2026 at 1:13 am
    NSDate *now = [NSDate date];
    int interval = 30*60; // half hour
    long int nowSeconds = (long int) [now timeIntervalSince1970];
    int secondsLeft = interval - (nowSeconds % interval); 
    NSDate *nextIntervalDate =  [NSDate 
        dateWithTimeIntervalSince1970:nowSeconds+secondsLeft];
    
    NSLog(@"Now is %@", now);
    NSLog(@"The next interval point in time is %@", nextIntervalDate);
    NSLog(@"That's another %d seconds (or %02d:%02d)", 
        secondsLeft, secondsLeft/60, secondsLeft%60);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to develop an iPhone/iPod application which runs in the background and can
Task: have a jailbroken iPhone need to write an application which would receive notifications
I have just heard that - push notification is possible in iPhone I need
I have three different development machines. Do I need three different iPhone Developer Program
I need to use Twitter api from iPhone 3.0 (SDK 3.0). can i use
I have some query. First of all let's have an iPhone application flow which
I need to do an iphone app that can look for a image pattern
I need to install an app into my iPhone, I have the .ipa file
I need than on button click opens iPhone's default album and I'll can chose
I have app , When i rotate clockwise direction of iphone i need to

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.