ElapsedDays.h头文件
#import <Foundation/Foundation.h>
@interface NSCalendarDate (ElapsedDays)
-(unsigned long) numberOfElapsedDays: (NSCalendarDate *) theDate;
@end
ElapsedDays.m源文件
#import "ElapsedDays.h"
#define IS_LEAP_YEAR(y) (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
@implementation NSCalendarDate (ElapsedDays)
-(unsigned long) numberOfElapsedDays: (NSCalendarDate *) theDate
{
int years, months, days;
unsigned long totDays = 0;
NSCalendarDate *minDate, *maxDate;
int maxDateYear, maxDateMonth, minDateYear, minDateMonth;
int dayPerMonth[12] = {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (self < theDate) {
minDate = self;
maxDate = theDate;
} else {
minDate = theDate;
maxDate = self;