gpt4 book ai didi

ios - 如何以编程方式计算 ios 中当前日期的下一个第 5 个工作日期

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:16:29 25 4
gpt4 key购买 nike

您好,我使用了 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);

最佳答案

你可以像这样使用 NSDateComponent 在一段时间后获取下一个日期

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com