Re: Running a function at a certain time
Re: Running a function at a certain time
- Subject: Re: Running a function at a certain time
- From: John Saccente <email@hidden>
- Date: Tue, 26 Feb 2002 19:27:43 -0600
This will set up a timer to fire at the time indicated by targetDate:
NSCalendarDate *currentDate;
NSCalendarDate *targetDate;
int secondsUntilTimerShouldFire;
currentDate = [NSCalendarDate calendarDate];
targetDate = [NSCalendarDate dateWithYear:2002 month:2 day:26
hour:19 minute:20 second:0
timeZone:[NSTimeZone localTimeZone]];
// fill the secondsUntilTimerShouldFire variable with the number of
seconds between the two dates
[targetDate years:NULL months:NULL days:NULL hours:NULL
minutes:NULL seconds:& secondsUntilTimerShouldFire
sinceDate:currentDate];
// fyi
NSLog(@"Current time: %@", currentDate);
NSLog(@"Target time: %@", targetDate);
NSLog(@"Seconds until timer: %d", secondsUntilTimerShouldFire);
timer = [NSTimer scheduledTimerWithTimeInterval:
secondsUntilTimerShouldFire
target:self
selector:@selector(myTimerFunc:)
userInfo:nil
repeats:NO];
[...]
- (void)myTimerFunc:(id)timer
{
NSLog(@"Timer fired");
}
John
On Tuesday, February 26, 2002, at 05:28 PM, Ben Mackin wrote:
I have been looking up and down Apple's website for how to check the
time,
and run a function at said time. I was looking at using cron, but that
seems
to be only able to run scripts and such, not parts of an application. I
can't seem to figure out how to even have an function like this in
cocoa.
In Carbon, it would be easy to throw something into the event loop, that
would poll for the time, and such. There has to be a way to do this in
cocoa, I just cant seem to find it.
Thanks
_______________________________________________
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.