我怎么能得到昨天的NSDate

Max*_*me 5 nsdate ios

我怎么能在iOS上获得昨天的NSDate?

谢谢

pro*_*rmr 15

这是一种方法:

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

NSDate *yesterday = [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:[NSDate date] options:0];
Run Code Online (Sandbox Code Playgroud)

请查看日期和时间编程指南.

  • 方法dateByAddingComponents*添加* (2认同)