最新下载
热门教程
- 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]]); }
这个方法不但可以获取星期,还可以获取当前年份,月份,时分秒等等。更多的方法可以进到方法里自己查看
相关文章
- 《魔兽世界》正式服中级骑术学习位置介绍 06-09
- Pi币TRC20币圈都在用的安装包盘点 Pi币TRC20APP入门选择十大排名 06-09
- 当前最值得购买的加密货币,全球加密货币大规模采用率不断上升 06-09
- 《纸嫁衣6千秋魇》第三章肖医生的家进入方法 06-09
- 《重装机兵3》大破坏密码大全 06-09
- 《剑灵2》搬砖系统介绍 06-09