这个仅仅是为了 获取当天所在周的周一是什么时间
- (NSString *)getMonthBeginAndEndWith:(NSDate *)newDate{
if (newDate == nil) {
newDate = [NSDate date];
}
double interval = 0;
NSDate *beginDate = nil;
NSDate *endDate = nil;
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar setFirstWeekday:2];//设定周一为周首日
////NSCalendarUnitWeekOfMonth 周
BOOL ok = [calendar rangeOfUnit:NSCalendarUnitWeekOfMonth startDate:&beginDate interval:&interval forDate:newDate];
//分别修改为 NSCalendarUnitDay NSWeekCalendarUnit NSYearCalendarUnit
//NSCalendarUnitWeekOfMonth or NSCalendarUnitWeekOfYear,
if (ok) {
endDate = [beginDate dateByAddingTimeInterval:interval-1];
}else {
return nil;
}
NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init];
[myDateFormatter setDateFormat:@"yyyyMMdd"];
NSString *beginString = [myDateFormatter stringFromDate:beginDate];
return beginString;
}
网友评论