我怎么能得到昨天的NSDate

时间:2011-08-25 22:32:17

标签: ios nsdate

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

由于

1 个答案:

答案 0 :(得分:15)

这是一种方法:

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

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

查看Date and Time programming guide