• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Synchronize timer with internal clock
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Synchronize timer with internal clock


  • Subject: Re: Synchronize timer with internal clock
  • From: "John C. Randolph" <email@hidden>
  • Date: Fri, 14 Mar 2003 09:55:03 -0800

On Friday, March 14, 2003, at 09:15 AM, Frank Fenn wrote:

Hi all,

is there an easy way to synchronize a NSTimer with the internal clock?
I've a NSTimer object that fires every 60 seconds but independent from
the program start time I would like to have the timer fired every minute
in sync with the system clock.

NSCalendarDate *now = [[NSCalendar date] date]; // get the current date

// round it to the next minute
NSCalendarDate *startDate = [now dateByAddingYears:0 months:0 days:0 hours:0 minutes:0 seconds:( 60 - [now secondOfMinute])];

NSTimer
*myTimer = [[NSTimer alloc]
initWithFireDate:startDate
interval:60
target:self
selector:@selector(minuteIsUp:)
userInfo:nil
repeats:YES];

...
- minuteIsUp:(NSTimer *)sender
{
// This gets called every minute
}

HTH,

-jcr

John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Synchronize timer with internal clock
      • From: Frank Fenn <email@hidden>
    • Re: Synchronize timer with internal clock
      • From: John Timmer <email@hidden>
References: 
 >Synchronize timer with internal clock (From: Frank Fenn <email@hidden>)

  • Prev by Date: Re: is there a way to extract text from pdfs?
  • Next by Date: NSAppleEventManager details ??
  • Previous by thread: Re: Synchronize timer with internal clock
  • Next by thread: Re: Synchronize timer with internal clock
  • Index(es):
    • Date
    • Thread