2013-04-18 65 views
0

我抓住當前時間IOS設置的UIDatePicker提前

NSDate * now = [[NSDate alloc] init]; 
NSCalendar *cal = [NSCalendar currentCalendar]; 
NSDateComponents * comps = [cal components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now]; 

而且我可以設置的DatePicker到我的願望

NSDate * date = [cal dateFromComponents:comps]; 
[self.off setDate:date animated:TRUE]; 

任何值,但我怎麼添加,比如,5分鐘到「現在」?

回答

2

試試這個

NSDate *date = [[NSDate date] dateByAddingTimeInterval:5*60]; 
+0

幾秒鐘快:) –

+0

@Julian似乎這樣:d – Anupdas

+0

你倆的岩石。感謝:D。 –

2

嘗試

NSDate *now = [NSDate dateWithTimeInterval:300 sinceDate:[NSDate date]]