ios 中有关当前日期,星期的获取
项目中用到了这些东西,分享出来让大家研究研究
//initializtion parameter
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now;
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
now=[NSDate date];
comps = [calendar components:unitFlags fromDate:now];
week = [comps weekday];
month = [comps month];
day = [comps day];
hour = [comps hour];
min = [comps minute];
sec = [comps second];
//Week: 在这一步耽误了不少时间!
1--星期天
2--星期一
3--星期二
4--星期三
5--星期四
6--星期五
7--星期六
http://www.cocoachina.com/bbs/read.php?tid-3377-fpage-2.html