ios提前设置UIDatePicker时间

时间:2013-04-18 11:08:16

标签: ios nsdate uidatepicker nscalendar nsdatecomponents

我抓住当前时间

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 个答案:

答案 0 :(得分:2)

试试这个

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

答案 1 :(得分:2)

尝试

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