码迷,mamicode.com
首页 > 移动开发 > 详细

IOS中由日期生成星期的一种方法

时间:2015-12-20 13:06:51      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

 1 - (NSInteger)getWeekDataWithYear:(NSString *)year month:(NSString *)month day:(NSString *)day{
 2    
 3     // 创建并设置NSDateComponents,它可以根据制定的时间生成对应的Date,同时需要根据相应的Calender
 4     NSDateComponents *comps = [[NSDateComponents alloc] init];
 5     [comps setDay:[day integerValue]];
 6     [comps setMonth:[month integerValue]];
 7     [comps setYear:[year integerValue]];
 8     // 创建Calender,格林威治时间,周日weekday是1以此类推
 9     NSCalendar *gregorian1 = [[NSCalendar alloc]
10                               initWithCalendarIdentifier:NSGregorianCalendar];
11     NSDate *date = [gregorian1 dateFromComponents:comps];
12     NSDateComponents *weekdayComponents =
13     [gregorian1 components:NSWeekdayCalendarUnit fromDate:date];
14     
15     NSInteger weekday = [weekdayComponents weekday];
16     
17     return weekday;
18 
19 }

 

IOS中由日期生成星期的一种方法

标签:

原文地址:http://www.cnblogs.com/Mike-Fighting/p/5060537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!