我正在使用
- (NSDate *)dateByAddingComponents:(NSDateComponents *)comps toDate:(NSDate *)date options:(NSCalendarOptions)opts
计算新日期,如下所示:
NSDateComponents *quaterComps = [NSDateComponents new];
quaterComps.quarter = 1;
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *nextDate = [gregorian dateByAddingComponents:quaterComps toDate:firstDate options:0];
当firstDate为2013-12-31 16:00:00 +0000时,
以上API不断返回相同的结果,而不是下一个季度
答案 0 :(得分:-1)
**当前日期和下一个日期**
NSDate *currentDate = [NSDate date];
NSDate *futureTime = [currentDate dateByAddingTimeInterval:60*60*72];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
[calendar setTimeZone:timeZone];
NSDateComponents *components = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit fromDate:futureTime];
if ([components hour] >= 19) { // make it the next day
[components setDay:[components day] + 1 ];
}
[components setHour:8];
[components setMinute:00];
NSDate *alertTime = [calendar dateFromComponents:components];
答案 1 :(得分:-1)
test2