0

我抓住当前时间

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 分钟?

4

2 回答 2

2

试试这个

NSDate *date = [[NSDate date] dateByAddingTimeInterval:5*60];
于 2013-04-18T11:10:42.793 回答
2

尝试

NSDate *now = [NSDate dateWithTimeInterval:300 sinceDate:[NSDate date]]
于 2013-04-18T11:11:10.417 回答