我怎么能得到昨天的NSDate

我怎么能得到昨天的NSDate

问题描述:

我如何在iOS上获得昨天的NSDate?

how I can get the NSDate of yesterday in iOS?

谢谢

这是一种方法:

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

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

看看日期和时间编程指南