开发者

Set a fixed date for a fireDate? xcode

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜