Re: Synchronize timer with internal clock
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.