5

Objective-Cで現在の年を取得するNSDate方法と、その年がうるう年かどうかを調べる方法は?

4

4 に答える 4

6

ウィキペディア:

if year is divisible by 400 then
   is_leap_year
else if year is divisible by 100 then
   not_leap_year
else if year is divisible by 4 then
   is_leap_year
else
   not_leap_year
于 2013-05-29T08:54:50.010 に答える
0
 NSDate *date = [NSDate date];
    NSLog(@"dat eis %@",date);

    NSDateFormatter *dateF = [[NSDateFormatter alloc]init];
    [dateF setDateFormat:@"YYYY"];
    NSString *dateS = [dateF stringFromDate:date ];
    NSLog(@"date is %@",dateS);

    int myInt = [dateS intValue];

    if(myInt%4== 0)

    {
        NSLog(@"Its a leap year ");
    }
    else{
        NSLog(@"Not A leap year");
    }
于 2013-05-30T05:04:50.577 に答える