I need to set several fireDates.开发者_运维百科 And I wonder how a set an alarm to an specific date and time?
NSDate *date = //set the date
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1000 target:target selector:@selector(aSelector) userInfo:userInfo repeats:NO];
[timer setFireDate:date];
or
NSDate *date = //set the date
NSTimer *timer = [[[NSTimer alloc] initWithFireDate::1000 target:target selector:@selector(aSelector) userInfo:userInfo repeats:NO] autorelease];
[timer setFireDate:date];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:currentMode];
I know its probably long overdue but here's my view on it :
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setHour:13];
[dateComponents setMinute:0];
[dateComponents setSecond:0];
[dateComponents setDay:17];
[dateComponents setMonth:12];
[dateComponents setYear:2012];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:components];
check this for better reference https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtCalendars.html
精彩评论