Jesse Meyer
Jesse Meyer

Reputation: 315

ios set UIDatePicker time ahead

I grab the current time

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

And I can set the DatePicker to any values I desire

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

But how do I add a, say, 5 minutes to "now"?

Upvotes: 0

Views: 320

Answers (2)

Julian F. Weinert
Julian F. Weinert

Reputation: 7560

Try

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

Upvotes: 2

Anupdas
Anupdas

Reputation: 10201

Try this

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

Upvotes: 2

Related Questions