iOS 日历NSCalendar初探

  • 获取系统事件和节日
    需要开启日历权限
    1
    2
    <key>NSCalendarsUsageDescription</key>
    <string>Ledemon需要您的同意,才能访问日历</string>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
EKEventStore *store = [[EKEventStore alloc] init];
__block typeof (self)weakSelf = self;
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError * _Nullable error) {
if (granted) {

NSDate *startDate = self.minimumDate; // 开始日期
NSDate *endDate = self.maximumDate; // 截止日期
NSPredicate *fetchCalendarEvents = [store predicateForEventsWithStartDate:startDate endDate:endDate calendars:nil];
NSArray<EKEvent *> *eventList = [store eventsMatchingPredicate:fetchCalendarEvents];
NSArray<EKEvent *> *events = [eventList filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(EKEvent * _Nullable event, NSDictionary<NSString *,id> * _Nullable bindings) {
return event.calendar.subscribed;
}]];
weakSelf.events = eventList;
}
}];
  • 可以使用第三方FSCalendar来显示日历 pod 'FSCalendar'

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    - (FSCalendar *)calendar {
    if (!_calendar) {
    // In loadView(Recommended) or viewDidLoad
    _calendar = [[FSCalendar alloc]init];
    _calendar.dataSource = self;
    _calendar.delegate = self;
    _calendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
    //设置周字体颜色
    _calendar.appearance.weekdayTextColor = [UIColor orangeColor];
    //设置头字体颜色
    _calendar.appearance.headerTitleColor = [UIColor blueColor];
    //设置翻页方式
    _calendar.scrollDirection = FSCalendarScrollDirectionVertical;
    //设置当天的背景颜色
    _calendar.appearance.todayColor = [UIColor redColor];


    //创建点击跳转显示上一月和下一月button
    UIButton *previousButton = [UIButton buttonWithType:UIButtonTypeCustom];
    previousButton.frame = CGRectMake(self.view.centerX - 60 - 20, 13, 20, 15);
    previousButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [previousButton setTitle:@"<<" forState:UIControlStateNormal];
    [previousButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [previousButton addTarget:self action:@selector(previousClicked:) forControlEvents:UIControlEventTouchUpInside];
    [_calendar addSubview:previousButton];

    UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    nextButton.frame = CGRectMake(self.view.centerX + 60, 13, 20, 15);
    nextButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [nextButton setTitle:@">>" forState:UIControlStateNormal];
    [nextButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    nextButton.imageView.transform = CGAffineTransformMakeRotation(M_PI);
    [nextButton addTarget:self action:@selector(nextClicked:) forControlEvents:UIControlEventTouchUpInside];
    [_calendar addSubview:nextButton];
    }
    return _calendar;
    }
  • NSDate转换方法

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    //根据date获取月
    - (NSInteger)convertDateToMonth:(NSDate *)date {
    NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitMonth) fromDate:date];
    return [components month];
    }

    //根据date获取当月总天数
    - (NSInteger)convertDateToTotalDays:(NSDate *)date {
    NSRange daysInOfMonth = [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:date];
    return daysInOfMonth.length;
    }

    //根据date获取偏移指定月数的date
    - (NSDate *)getDateFrom:(NSDate *)date offsetMonths:(NSInteger)offsetMonths {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM"];

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *lastMonthComps = [[NSDateComponents alloc] init];
    [lastMonthComps setMonth:offsetMonths]; //year = 1表示1年后的时间 year = -1为1年前的日期,month day 类推
    NSDate *newdate = [calendar dateByAddingComponents:lastMonthComps toDate:date options:0];
    return newdate;
    }
  • FSCalendar 的代理方法

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    // 某个日期的所有事件
    - (NSArray<EKEvent *> *)eventsForDate:(NSDate *)date {
    NSArray<EKEvent *> *filteredEvents = [self.events filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(EKEvent * _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
    return [evaluatedObject.occurrenceDate isEqualToDate:date];
    }]];
    return filteredEvents;
    }

    //副标题显示
    - (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date {
    EKEvent *event = [self eventsForDate:date].firstObject;
    if (event) {
    return event.title; // 春分、秋分、儿童节、植树节、国庆节、圣诞节...
    }
    NSInteger lunarDay = [self.chineseCalendar component:NSCalendarUnitDay fromDate:date];
    return _lunarChars[lunarDay-1];
    }

    //更新view
    - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated {
    [UIView animateWithDuration:0.3f animations:^{
    [calendar mas_updateConstraints:^(MASConstraintMaker *make) {
    make.height.equalTo(@(bounds.size.height));
    // Do other updates
    }];
    [self.view layoutIfNeeded];
    }];
    }
  • 如果不想使用系统节假日,可以自己封装Manager

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    #define ChineseMonths @[@"正月", @"二月", @"三月", @"四月", @"五月", @"六月", @"七月", @"八月",@"九月", @"十月", @"冬月", @"腊月"]
    #define ChineseFestival @[@"除夕",@"春节",@"中秋",@"五一",@"国庆",@"儿童",@"圣诞",@"七夕",@"端午"]
    #define ChineseDays @[@"初一", @"初二", @"初三", @"初四", @"初五", @"初六", @"初七", @"初八", @"初九", @"初十",@"十一", @"十二", @"十三", @"十四", @"十五", @"十六", @"十七", @"十八", @"十九", @"二十", @"廿一", @"廿二", @"廿三", @"廿四", @"廿五", @"廿六", @"廿七", @"廿八", @"廿九", @"三十"]
    #define ChineseWeatherFestival @[@"立春",@"雨水",@"惊蛰",@"春分",@"清明",@"谷雨",@"立夏",@"小满",@"忙种",@"夏至",@"小暑",@"大暑",@"立秋",@"处暑",@"寒露",@"霜降",@"白露",@"秋分",@"立冬",@"小雪",@"大雪",@"冬至",@"小寒",@"大寒"]

    {
    NSString *_day;
    }
    // 获取date当天的农历
    - (NSString *)chineseCalendarOfDate:(NSDate *)date {

    NSCalendar *chineseCalendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierChinese];
    NSDateComponents *components = [chineseCalendar components:NSCalendarUnitYear |NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date];
    //NSString *dayDate;
    NSCalendar *normalDate = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *Datecomponents = [normalDate components:NSCalendarUnitYear |NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date];

    if (components.day ==1 ) {
    _day =ChineseMonths[components.month -1];

    } else {

    _day =ChineseDays[components.day -1];
    }
    //农历节日

    if (components.day ==1 && components.month ==1) {
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[1]]; //春节
    } if(components.month ==8 && components.day ==15){
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[2]];//中秋
    }else if(components.day ==30 && components.month ==12){
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[0]];//除夕
    }else if(components.month ==7 && components.day ==7){
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[7]];//七夕
    }else if(components.month ==5 && components.day ==5){
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[8]];//端午
    }
    //阳历节日
    if (Datecomponents.month ==6 && Datecomponents.day ==1) { //儿童节
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[5]];
    }else if(Datecomponents.month ==10 && Datecomponents.day ==1){ //国庆节
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[4]];
    }else if(Datecomponents.month ==5 && Datecomponents.day ==1){ //劳动节
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[3]];
    }else if(Datecomponents.month ==12 && Datecomponents.day ==25){//圣诞节
    _day = [NSString stringWithFormat:@"%@",ChineseFestival[6]];
    }


    [self getLunarSpecialDate:Datecomponents.year Month:Datecomponents.month Day:Datecomponents.day];
    //除夕另外提出放在所有节日的末尾执行,除夕是在春节前一天,即把components当天时间前移一天,放在所有节日末尾,避免其他节日全部前移一天
    NSTimeInterval timeInterval_day =60 *60 *24;
    NSDate *nextDay_date = [NSDate dateWithTimeInterval:timeInterval_day sinceDate:date];
    NSCalendar *localeCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSChineseCalendar];
    unsigned unitFlags =NSYearCalendarUnit |NSMonthCalendarUnit |NSDayCalendarUnit;
    components = [localeCalendar components:unitFlags fromDate:nextDay_date];
    if ( 1 == components.month &&1 == components.day ) {
    return @"除夕";
    }
    return _day;
    }

    //24节气只有(1901 - 2050)之间为准确的节气
    const int START_YEAR =1901;
    const int END_YEAR =2050;

    static int32_t gLunarHolDay[] = {
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1901
    0X96,0XA4,0X96,0X96,0X97,0X87,0X79,0X79,0X79,0X69,0X78,0X78, //1902
    0X96,0XA5,0X87,0X96,0X87,0X87,0X79,0X69,0X69,0X69,0X78,0X78, //1903
    0X86,0XA5,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X78,0X87, //1904
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1905
    0X96,0XA4,0X96,0X96,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X78, //1906
    0X96,0XA5,0X87,0X96,0X87,0X87,0X79,0X69,0X69,0X69,0X78,0X78, //1907
    0X86,0XA5,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1908
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1909
    0X96,0XA4,0X96,0X96,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X78, //1910
    0X96,0XA5,0X87,0X96,0X87,0X87,0X79,0X69,0X69,0X69,0X78,0X78, //1911
    0X86,0XA5,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1912
    0X95,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1913
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X78, //1914
    0X96,0XA5,0X97,0X96,0X97,0X87,0X79,0X79,0X69,0X69,0X78,0X78, //1915
    0X96,0XA5,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1916
    0X95,0XB4,0X96,0XA6,0X96,0X97,0X78,0X79,0X78,0X69,0X78,0X87, //1917
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X77, //1918
    0X96,0XA5,0X97,0X96,0X97,0X87,0X79,0X79,0X69,0X69,0X78,0X78, //1919
    0X96,0XA5,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1920
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X78,0X79,0X78,0X69,0X78,0X87, //1921
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X77, //1922
    0X96,0XA4,0X96,0X96,0X97,0X87,0X79,0X79,0X69,0X69,0X78,0X78, //1923
    0X96,0XA5,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1924
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X78,0X79,0X78,0X69,0X78,0X87, //1925
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1926
    0X96,0XA4,0X96,0X96,0X97,0X87,0X79,0X79,0X79,0X69,0X78,0X78, //1927
    0X96,0XA5,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1928
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1929
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1930
    0X96,0XA4,0X96,0X96,0X97,0X87,0X79,0X79,0X79,0X69,0X78,0X78, //1931
    0X96,0XA5,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1932
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1933
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1934
    0X96,0XA4,0X96,0X96,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X78, //1935
    0X96,0XA5,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1936
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1937
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1938
    0X96,0XA4,0X96,0X96,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X78, //1939
    0X96,0XA5,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1940
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1941
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1942
    0X96,0XA4,0X96,0X96,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X78, //1943
    0X96,0XA5,0X96,0XA5,0XA6,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1944
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1945
    0X95,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X78,0X69,0X78,0X77, //1946
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X78, //1947
    0X96,0XA5,0XA6,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //1948
    0XA5,0XB4,0X96,0XA5,0X96,0X97,0X88,0X79,0X78,0X79,0X77,0X87, //1949
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X78,0X79,0X78,0X69,0X78,0X77, //1950
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X79,0X79,0X79,0X69,0X78,0X78, //1951
    0X96,0XA5,0XA6,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //1952
    0XA5,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1953
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X78,0X79,0X78,0X68,0X78,0X87, //1954
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1955
    0X96,0XA5,0XA5,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //1956
    0XA5,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1957
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1958
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1959
    0X96,0XA4,0XA5,0XA5,0XA6,0X96,0X88,0X88,0X88,0X78,0X87,0X87, //1960
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1961
    0X96,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1962
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1963
    0X96,0XA4,0XA5,0XA5,0XA6,0X96,0X88,0X88,0X88,0X78,0X87,0X87, //1964
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1965
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1966
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1967
    0X96,0XA4,0XA5,0XA5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //1968
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1969
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1970
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X79,0X69,0X78,0X77, //1971
    0X96,0XA4,0XA5,0XA5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //1972
    0XA5,0XB5,0X96,0XA5,0XA6,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1973
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1974
    0X96,0XB4,0X96,0XA6,0X97,0X97,0X78,0X79,0X78,0X69,0X78,0X77, //1975
    0X96,0XA4,0XA5,0XB5,0XA6,0XA6,0X88,0X89,0X88,0X78,0X87,0X87, //1976
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //1977
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X78,0X87, //1978
    0X96,0XB4,0X96,0XA6,0X96,0X97,0X78,0X79,0X78,0X69,0X78,0X77, //1979
    0X96,0XA4,0XA5,0XB5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //1980
    0XA5,0XB4,0X96,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X77,0X87, //1981
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1982
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X78,0X79,0X78,0X69,0X78,0X77, //1983
    0X96,0XB4,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X87, //1984
    0XA5,0XB4,0XA6,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //1985
    0XA5,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //1986
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X79,0X78,0X69,0X78,0X87, //1987
    0X96,0XB4,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //1988
    0XA5,0XB4,0XA5,0XA5,0XA6,0X96,0X88,0X88,0X88,0X78,0X87,0X87, //1989
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X79,0X77,0X87, //1990
    0X95,0XB4,0X96,0XA5,0X86,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1991
    0X96,0XB4,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //1992
    0XA5,0XB3,0XA5,0XA5,0XA6,0X96,0X88,0X88,0X88,0X78,0X87,0X87, //1993
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1994
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X76,0X78,0X69,0X78,0X87, //1995
    0X96,0XB4,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //1996
    0XA5,0XB3,0XA5,0XA5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //1997
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //1998
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //1999
    0X96,0XB4,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //2000
    0XA5,0XB3,0XA5,0XA5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //2001
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //2002
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //2003
    0X96,0XB4,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //2004
    0XA5,0XB3,0XA5,0XA5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //2005
    0XA5,0XB4,0X96,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //2006
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X69,0X78,0X87, //2007
    0X96,0XB4,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X87,0X78,0X87,0X86, //2008
    0XA5,0XB3,0XA5,0XB5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //2009
    0XA5,0XB4,0X96,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //2010
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X78,0X87, //2011
    0X96,0XB4,0XA5,0XB5,0XA5,0XA6,0X87,0X88,0X87,0X78,0X87,0X86, //2012
    0XA5,0XB3,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X87, //2013
    0XA5,0XB4,0X96,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //2014
    0X95,0XB4,0X96,0XA5,0X96,0X97,0X88,0X78,0X78,0X79,0X77,0X87, //2015
    0X95,0XB4,0XA5,0XB4,0XA5,0XA6,0X87,0X88,0X87,0X78,0X87,0X86, //2016
    0XA5,0XC3,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X87, //2017
    0XA5,0XB4,0XA6,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //2018
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X79,0X77,0X87, //2019
    0X95,0XB4,0XA5,0XB4,0XA5,0XA6,0X97,0X87,0X87,0X78,0X87,0X86, //2020
    0XA5,0XC3,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //2021
    0XA5,0XB4,0XA5,0XA5,0XA6,0X96,0X88,0X88,0X88,0X78,0X87,0X87, //2022
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X79,0X77,0X87, //2023
    0X95,0XB4,0XA5,0XB4,0XA5,0XA6,0X97,0X87,0X87,0X78,0X87,0X96, //2024
    0XA5,0XC3,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //2025
    0XA5,0XB3,0XA5,0XA5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //2026
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //2027
    0X95,0XB4,0XA5,0XB4,0XA5,0XA6,0X97,0X87,0X87,0X78,0X87,0X96, //2028
    0XA5,0XC3,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //2029
    0XA5,0XB3,0XA5,0XA5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //2030
    0XA5,0XB4,0X96,0XA5,0X96,0X96,0X88,0X78,0X78,0X78,0X87,0X87, //2031
    0X95,0XB4,0XA5,0XB4,0XA5,0XA6,0X97,0X87,0X87,0X78,0X87,0X96, //2032
    0XA5,0XC3,0XA5,0XB5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X86, //2033
    0XA5,0XB3,0XA5,0XA5,0XA6,0XA6,0X88,0X78,0X88,0X78,0X87,0X87, //2034
    0XA5,0XB4,0X96,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //2035
    0X95,0XB4,0XA5,0XB4,0XA5,0XA6,0X97,0X87,0X87,0X78,0X87,0X96, //2036
    0XA5,0XC3,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X86, //2037
    0XA5,0XB3,0XA5,0XA5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //2038
    0XA5,0XB4,0X96,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //2039
    0X95,0XB4,0XA5,0XB4,0XA5,0XA6,0X97,0X87,0X87,0X78,0X87,0X96, //2040
    0XA5,0XC3,0XA5,0XB5,0XA5,0XA6,0X87,0X88,0X87,0X78,0X87,0X86, //2041
    0XA5,0XB3,0XA5,0XB5,0XA6,0XA6,0X88,0X88,0X88,0X78,0X87,0X87, //2042
    0XA5,0XB4,0X96,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //2043
    0X95,0XB4,0XA5,0XB4,0XA5,0XA6,0X97,0X87,0X87,0X88,0X87,0X96, //2044
    0XA5,0XC3,0XA5,0XB4,0XA5,0XA6,0X87,0X88,0X87,0X78,0X87,0X86, //2045
    0XA5,0XB3,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X88,0X78,0X87,0X87, //2046
    0XA5,0XB4,0X96,0XA5,0XA6,0X96,0X88,0X88,0X78,0X78,0X87,0X87, //2047
    0X95,0XB4,0XA5,0XB4,0XA5,0XA5,0X97,0X87,0X87,0X88,0X86,0X96, //2048
    0XA4,0XC3,0XA5,0XA5,0XA5,0XA6,0X97,0X87,0X87,0X78,0X87,0X86, //2049
    0XA5,0XC3,0XA5,0XB5,0XA6,0XA6,0X87,0X88,0X78,0X78,0X87,0X87 //2050

    };
    -(NSString *)getLunarSpecialDate:(NSInteger)iYear Month:(NSInteger)iMonth Day:(NSInteger)iDay {
    NSArray *chineseDays=[NSArray arrayWithObjects:
    @"小寒",@"大寒",@"立春",@"雨水",@"惊蛰",@"春分",
    @"清明",@"谷雨",@"立夏",@"小满",@"芒种",@"夏至",
    @"小暑",@"大暑",@"立秋",@"处暑",@"白露",@"秋分",
    @"寒露",@"霜降",@"立冬",@"小雪",@"大雪",@"冬至",nil];
    long array_index = (iYear -START_YEAR)*12+iMonth -1;
    int64_t flag =gLunarHolDay[array_index];
    int64_t day;
    if(iDay <15)
    day= 15 - ((flag>>4)&0x0f);
    else
    day = ((flag)&0x0f)+15;
    long index = -1;
    if(iDay == day){
    index = (iMonth-1) *2 + (iDay>15?1:0);
    }
    if ( index >=0 && index < [chineseDays count] ) {
    [chineseDays objectAtIndex:index];
    //NSLog(@"%@",chineseDays[index]);
    _day = chineseDays[index];
    return _day;
    } else {
    return nil;
    }
    }
本文总阅读量