在我的应用程序中,我有下一周和上周按钮,但也有UIDatePicker。那么让我说按净周按钮,如何调整UIDatePicker中的日期增加7天?反过来7天也是如此。
谢谢!
答案 0 :(得分:1)
使用dateByAddingTimeInterval:
类的NSDate
方法和setDate:animated:
类的UIDatePicker
方法来调整选择器的当前日期:
NSDate *currentDate = [datePicker date];
// Set the date 7 days earlier
NSDate *sevenDaysEarlier = [currentDate dateByAddingTimeInterval:-(60 * 60 * 24 * 7)];
[datePicker setDate:sevenDaysEarlier animated:YES];
// Set the date 7 days later
NSDate *sevenDaysLater = [currentDate dateByAddingTimeInterval:60 * 60 * 24 * 7];
[datePicker setDate:sevenDaysLater animated:YES];