làm thế nào tôi có thể nhận được NSDate của ngày hôm qua trong iOS?Làm thế nào tôi có thể nhận được NSDate của ngày hôm qua
Cảm ơn
làm thế nào tôi có thể nhận được NSDate của ngày hôm qua trong iOS?Làm thế nào tôi có thể nhận được NSDate của ngày hôm qua
Cảm ơn
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.
http://stackoverflow.com/questions/1889164/get-nsdate-today-yesterday-this-week-last-week-this-month-last-month-vari –