最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
iOS开发之获取当前星期程序代码
时间:2022-06-25 23:45:11 编辑:袖梨 来源:一聚教程网
把当前的日期转换为星期几
- (void)getWeek
{
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:[NSDate date]];
int year=[comps year];
int week = [comps weekday];
int month = [comps month];
int day = [comps day];
int hour = [comps hour];
int min = [comps minute];
int sec = [comps second];
NSArray * arrWeek=[NSArray arrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六", nil];
NSLog(@"星期:%@", [NSString stringWithFormat:@"%@",[arrWeek objectAtIndex:[comps weekday] - 1]]);
}
这个方法不但可以获取星期,还可以获取当前年份,月份,时分秒等等。更多的方法可以进到方法里自己查看
相关文章
- 将军留步最厉害三个阵容—最强阵容推荐 09-07
- 小小仙王清凉版本免费下载 无遮挡版本下载 09-07
- 天阶岛最厉害三个角色 英雄排行榜一览 09-07
- 大店小二0.1折下载—折扣平台在哪下载 09-07
- tplink路由器wr886n怎么设置桥接(tplink路由器wr886n设置桥接方法) 09-07
- 武侠大明星破解版免广告-mod作弊菜单 09-07