Ishu Ishu - 5 months ago 10
iOS Question

Subtract minutes from NSDate

I want to subtract some minutes 15 min 10 min etc., And i am having date object with time now i want to subtract minutes.

Answer

Check out my answer to this question: NSDate substract one month

Here's a sample, modified for your question:

NSDate *today = [[NSDate alloc] init];
NSLog(@"%@", today);
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setMinute:-10]; // note that I'm setting it to -1
NSDate *endOfWorldWar3 = [gregorian dateByAddingComponents:offsetComponents toDate:today options:0];
NSLog(@"%@", endOfWorldWar3);

Hope this helps!

Comments