tags:

views:

238

answers:

1

I'm trying to get nsdate from uidatepicker, but it constantly returns me a date time with trailing 20 seconds. How can I manually set NSDate's second to zero?

+3  A: 

NSDate is immutable, so you cannot modify its time. But you can create a new date object that snaps to the nearest minute:

NSTimeInterval time = round([date timeIntervalSinceReferenceDate] / 60.0) * 60.0;
NSDate *minute = [NSDate dateWithTimeIntervalSinceReferenceDate:time];
Nikolai Ruhe