2011-08-25 28 views

Trả lời

15

Dưới đây là một cách để làm điều đó:

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

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

Hãy nhìn vào các Date and Time programming guide.

+0

Không trừ một số âm làm cho nó thêm 1 ngày? – honcheng

+2

Phương thức dateByAddingComponents * thêm * – progrmr

+0

@progrmr, Cảm ơn rất nhiều. –

Các vấn đề liên quan