美文网首页
阳历 -- > 阴历

阳历 -- > 阴历

作者: Rayla_周周 | 来源:发表于2016-09-19 11:11 被阅读0次

    - (NSString *)getChineseCalendarWithDate:(NSInteger)day month:(NSInteger)month year:(NSInteger)year{

    NSArray *chineseDays=[NSArray arrayWithObjects:

    @"初一", @"初二", @"初三", @"初四", @"初五", @"初六", @"初七", @"初八", @"初九", @"初十",

    @"十一", @"十二", @"十三", @"十四", @"十五", @"十六", @"十七", @"十八", @"十九", @"二十",

    @"廿一", @"廿二", @"廿三", @"廿四", @"廿五", @"廿六", @"廿七", @"廿八", @"廿九", @"三十",  nil];

    NSString* string;

    if(month<10)

    {

    if (day < 10) {

    string = [NSString stringWithFormat:@"%ld0%ld0%ld23",year,month,day];

    }

    else{

    string = [NSString stringWithFormat:@"%ld0%ld%ld23",year,month,day];

    }

    }

    else

    {

    if (day < 10) {

    string = [NSString stringWithFormat:@"%ld%ld0%ld23",year,month,day];

    }

    else{

    string = [NSString stringWithFormat:@"%ld%ld%ld23",year,month,day];

    }

    }

    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];

    [inputFormatter setDateFormat:@"yyyyMMddHH"];

    NSDate* inputDate = [inputFormatter dateFromString:string];

    NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];

    unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay;

    NSDateComponents *localeComp = [localeCalendar components:unitFlags fromDate:inputDate];

    NSString *d_str = [chineseDays objectAtIndex:localeComp.day-1];

    return d_str;

    }

    相关文章

      网友评论

          本文标题:阳历 -- > 阴历

          本文链接:https://www.haomeiwen.com/subject/rqtnettx.html