根据日期判断星期几
2016-08-08 13:56
316 查看
根据日期判断星期几
[_comps setDay:23];
[_comps setMonth:3];
[_comps setYear:2014];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *_date = [gregorian dateFromComponents:_comps];
NSDateComponents *weekdayComponents =
[gregorian components:NSWeekdayCalendarUnit fromDate:_date];
int _weekday = [weekdayComponents weekday];
NSLog(@"_weekday::%d",_weekday);
2、
+ (NSInteger)acquireWeekDayFromDate:(NSDate*)date {
NSCalendar* calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitWeekday;
NSDateComponents* comps = [calendar components:unitFlags fromDate:date];
return [comps weekday];
}
//在这里需要注意的是:星期日是数字1,星期一时数字2,以此类推
[_comps setDay:23];
[_comps setMonth:3];
[_comps setYear:2014];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *_date = [gregorian dateFromComponents:_comps];
NSDateComponents *weekdayComponents =
[gregorian components:NSWeekdayCalendarUnit fromDate:_date];
int _weekday = [weekdayComponents weekday];
NSLog(@"_weekday::%d",_weekday);
2、
+ (NSInteger)acquireWeekDayFromDate:(NSDate*)date {
NSCalendar* calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitWeekday;
NSDateComponents* comps = [calendar components:unitFlags fromDate:date];
return [comps weekday];
}
//在这里需要注意的是:星期日是数字1,星期一时数字2,以此类推
相关文章推荐
- C语言根据日期判断星期几(使用基姆拉尔森计算公式)
- C语言根据日期判断星期几
- 菜鸟成长记-根据输入的日期判断星期几
- inputs a date (e.g. July 4, 2008) and outputs the day of the week-根据输入日期判断星期几
- C语言判断日期有效性以及根据年月日输出星期几
- javascript根据日期判断星期几
- 根据日期判断星期几(使用基姆拉尔森计算公式)
- 根据日期判断是星期几
- jquery 获得星期几-根据当前日期判断是星期几
- C语言根据日期(年,月,日)判断星期几(使用基姆拉尔森计算公式)
- 根据当前日期判断星期几
- 根据日期判断是星期几(zeller公式)
- C语言根据日期判断星期几(使用基姆拉尔森计算公式)
- C++ 根据日期判断星期几
- C:根据日期判断是一年的第几天、星期几
- 根据给定日期判断当天是星期几
- 给定日期,判断是星期几
- 根据“年月日”字符串,判断这一天是星期几
- angular4自定义根据日期判断星期的管道
- oracle中如何判断某个日期是星期几