我怎样才能得到即将到来的日期 - 目标C.

Vai*_*ran 0 objective-c nsdate nsdateformatter ios6.1

如果我说upcoming monday那我怎么能得到约会upcoming monday

比如,今天Thu, 04-04-2013我怎么能得到即将到来的日期wednesday

希望我能澄清你.

这里问了类似的问题,但我无法理解这一点:

在Objective-C中获取下周六的日期?

Ano*_*dya 6

NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [NSDate date];
NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:date];
NSInteger todayWeekday = [weekdayComponents weekday];

enum Weeks {
    SUNDAY = 1,
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY
};

NSInteger moveDays=WEDNESDAY-todayWeekday;
if (moveDays<=0) {
    moveDays+=7;
}

NSDateComponents *components = [NSDateComponents new];
components.day=moveDays;

NSCalendar *calendar=[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDate* newDate = [calendar dateByAddingComponents:components toDate:date options:0];

NSLog(@"%@",newDate);
Run Code Online (Sandbox Code Playgroud)