【发布时间】:2011-08-25 22:32:16
【问题描述】:
如何在 iOS 中获取昨天的 NSDate?
谢谢
【问题讨论】:
如何在 iOS 中获取昨天的 NSDate?
谢谢
【问题讨论】:
这是一种方法:
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:-1];
NSDate *yesterday = [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:[NSDate date] options:0];
【讨论】:
components 而不是 componentsToSubtract,因为我们实际上是在此处添加。