问题
how I can get the NSDate of yesterday in iOS?
Thanks
回答1:
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.
来源:https://stackoverflow.com/questions/7197994/how-i-can-get-the-nsdate-of-yesterday