Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can get the NSDate of yesterday

Tags:

ios

nsdate

how I can get the NSDate of yesterday in iOS?

Thanks

like image 287
Maxime Avatar asked Aug 25 '11 22:08

Maxime


1 Answers

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.

like image 170
progrmr Avatar answered Nov 11 '22 14:11

progrmr