5

how I can get the NSDate of yesterday in iOS?

Thanks

Maxime
  • 3,167
  • 7
  • 26
  • 33
  • http://stackoverflow.com/questions/1889164/get-nsdate-today-yesterday-this-week-last-week-this-month-last-month-vari – Book Of Zeus Aug 27 '11 at 15:18

1 Answers1

15

Here is one way to do that:

NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:-1];

NSDate *yesterday = [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:[NSDate date] options:0];

Take a look at the Date and Time programming guide.

progrmr
  • 75,956
  • 16
  • 112
  • 147