如何在iphone中找出当年是否闰年
发布时间:2020-12-14 18:58:26 所属栏目:百科 来源:网络整理
导读:参见英文答案 How do I calculate the number of days in this year in Objective C????????????????????????????????????11个 如何从NSDate获取当前年份以及如何在Objective-C中找出那一年是否是闰年? 解决方法 您可以执行以下操作: - (BOOL)isYearLeapYe
参见英文答案 >
How do I calculate the number of days in this year in Objective C????????????????????????????????????11个
如何从NSDate获取当前年份以及如何在Objective-C中找出那一年是否是闰年? 解决方法
您可以执行以下操作:
- (BOOL)isYearLeapYear:(NSDate *) aDate { NSInteger year = [self yearFromDate:aDate]; return (( year%100 != 0) && (year%4 == 0)) || year%400 == 0; } - (NSInteger)yearFromDate:(NSDate *)aDate { NSDateFormatter *dateFormatter = [NSDateFormatter new]; dateFormatter.dateFormat = @"yyyy"; NSInteger year = [[dateFormatter stringFromDate:aDate] integerValue]; return year; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |