我需要设置几个fireDates。我想知道如何在特定的日期和时间设置闹钟?
答案 0 :(得分:1)
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];
答案 1 :(得分:0)
我知道这可能早就应该了,但是我的观点是:
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];
选中此选项以获得更好的参考https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtCalendars.html