一,代码。
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. NSLog(@"8月的天数%ld",(long)[self getCurrentDay:8]); }
#pragma -mark -functions
//获得当前的月的天数
-(NSInteger )getCurrentDay:(int) currentMonth{
if (currentMonth < 8 ) {
if (currentMonth %2 ==1) {
return 31;
}else{
return 30;
}
}else{
if (currentMonth %2 ==1) {
return 30;
}else{
return 31;
}
} } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
二,输出。
2015-10-19 13:33:04.785 获得当前的月的天数[5116:115173] 8月的天数31