您好,我使用过 NSDateComponents 但无法计算第 5 个日期
NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [calendar components:NSWeekdayCalendarUnit | NSHourCalendarUnit fromDate:now];
NSInteger weekday = [dateComponents weekday];
NSLog(@"Week %ld",(long)weekday);
您可以像这样使用 NSDateComponents 在某个时间间隔后获取下一个日期
NSDateComponents *dateComponents = [NSDateComponents new];
dateComponents.minute = 15; //to get time after 15 minutes
dateComponents.day = 5; //to get date after 5 days
//and similarly you can calculate date or time after hour, minute, seconds day, week, etc
NSDate *date = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents toDate:[formatterWithAM dateFromString:startTime.text] options:0]
关于ios - 如何以编程方式从 ios 中的当前日期计算下一个第 5 个工作日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29430560/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |