2011-10-13 61 views

回答

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]; 
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