NSDate* today = [NSDate date];
double intervalweek = 0;
double intervalmonth = 0;
NSDate *WeekbeginDate = nil;
NSDate *WeekendDate = nil;
NSDate *MonthbeginDate = nil;
NSDate *MonthendDate = nil;
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar setFirstWeekday:2];//设定周一为周首日
BOOL ok = [calendar rangeOfUnit:NSCalendarUnitWeekOfMonth startDate:&WeekbeginDate interval:&intervalweek forDate:today];
BOOL ok2 = [calendar rangeOfUnit:NSCalendarUnitMonth startDate:&MonthbeginDate interval:&intervalmonth forDate:today];
//分别修改为 NSDayCalendarUnit NSWeekCalendarUnit NSYearCalendarUnit
if (ok) {
WeekendDate = [WeekbeginDate dateByAddingTimeInterval:intervalweek-1];
}else{
return nil;
}
if (ok2) {
MonthendDate = [MonthbeginDate dateByAddingTimeInterval:intervalmonth-1];
}else {
return nil;
}
NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init];
[myDateFormatter setDateFormat:@"yyyy-MM-dd EEEE"];
NSString *WeekbeginString = [myDateFormatter stringFromDate:WeekbeginDate];
NSString *WeekendString = [myDateFormatter stringFromDate:WeekendDate];
NSString* MonthbeginString = [myDateFormatter stringFromDate:MonthbeginDate];
NSString* MonthendString = [myDateFormatter stringFromDate:MonthendDate];
BINLog(@"本周开始结束%@-%@ 本月开始结束%@-%@",WeekbeginString,WeekendString,MonthbeginString,MonthendString);
本周,本月筛选方法
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...