0
我需要設置幾個fireDates。我想知道如何設置一個特定日期和時間的鬧鐘?設置fireDate的固定日期? xcode
我需要設置幾個fireDates。我想知道如何設置一個特定日期和時間的鬧鐘?設置fireDate的固定日期? xcode
NSDate *date = //set the date
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1000 target:target selector:@selector(aSelector) userInfo:userInfo repeats:NO];
[timer setFireDate:date];
或
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];
我知道它可能是姍姍來遲,但這裏是我的觀點就可以了:
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];