问题描述
我正在尝试列出给定月份的所有星期 喜欢 开始日期2020年9月6日 结束日期2020年9月12日
,如果一个星期在下个月结束,则还应显示该日期 喜欢 开始日期2020年9月27日 结束日期2020年10月3日
一个将NSDate作为输入并使用NSArray或NSDictionary返回日期数组(星期的开始和结束日期)的函数,只要给定NSDate的开始和结束日期,任何东西都可以工作
我已经尝试过DateTools,Datz和其他Pod,但仍然无法获得
-(void) getWeeksOfTheMonthCurrent {
NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *oneDayAgoComponents = [[NSDateComponents alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
for(int currentdateindexpath=0;currentdateindexpath<=10currentdateindexpath++)
{
NSDateComponents* subcomponent = [calendar components:NSCalendarUnitWeekday
fromDate:[NSDate date]];
[oneDayAgoComponents setDay: 0 - ([subcomponent weekday] - 1)];
NSDate *beginningOfWeek = [calendar dateByAddingComponents:oneDayAgoComponents
toDate:[NSDate date] options:0];
[formatter setDateFormat:@"dd/MM/yy"];
NSString *weekstartdate = [formatter stringFromDate:beginningOfWeek];
NSLog(@"weekstartdate %@",weekstartdate);
NSDateComponents *components =
[calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth |
NSCalendarUnitDay) fromDate: beginningOfWeek];
beginningOfWeek = [calendar dateFromComponents:components];
[oneDayAgoComponents setDay:7- ([subcomponent weekday])];
NSDate *endOfWeek = [calendar dateByAddingComponents:oneDayAgoComponents
toDate:[NSDate date] options:0];
[formatter setDateFormat:@"dd/MM/yy"];
NSString *weekendtdate = [formatter stringFromDate:endOfWeek];
NSLog(@"weekendtdate %@",weekendtdate);
}
}
我已经尝试过使用此代码来获取开始日期和结束日期,但这不是我想要的 我只是想要一个以NSDate作为参数并返回包含开始日期和结束日期的对象数组的函数
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)