//#define ChineseMonths @[@"正月", @"二月", @"三月", @"四月", @"五月", @"六月", @"七月", @"八月",@"九月", @"十月", @"冬月", @"腊月"]
//#define WeekDays @[@" ",@"星期日",@"星期一",@"星期二", @"星期三", @"星期四", @"星期五", @"星期六", @" "]
//#define ChineseFestival @[@"春节",@"元宵",@"端午",@"七夕",@"中元",@"中秋",@"重阳",@"腊八",@"小年",@"元旦",@"情人节", @"妇女节",@"劳动节",@"儿童节",@"建军节",@"教师节",@"国庆节",@"程序员日",@"植树节",@"光棍节",@"圣诞节",@"小寒", @"大寒", @"立春", @"雨水", @"惊蛰", @"春分",@"清明", @"谷雨", @"立夏", @"小满", @"芒种", @"夏至",@"小暑", @"大暑", @"立秋", @"处暑", @"白露", @"秋分",@"寒露", @"霜降", @"立冬", @"小雪", @"大雪", @"冬至"]
//#define ChineseDays @[@"初一", @"初二", @"初三", @"初四", @"初五", @"初六", @"初七", @"初八", @"初九", @"初十",@"十一", @"十二", @"十三", @"十四", @"十五", @"十六", @"十七", @"十八", @"十九", @"二十", @"廿一", @"廿二", @"廿三", @"廿四", @"廿五", @"廿六", @"廿七", @"廿八", @"廿九", @"三十"]
//#define ChineseWeatherFestival @[@"立春",@"雨水",@"惊蛰",@"春分",@"清明",@"谷雨",@"立夏",@"小满",@"忙种",@"夏至",@"小暑",@"大暑",@"立秋",@"处暑",@"寒露",@"霜降",@"白露",@"秋分",@"立冬",@"小雪",@"大雪",@"冬至",@"小寒",@"大寒"]
@implementation CalendarLogic
#pragma mark - 获取某天农历
+ (NSString*)getChineseCalendarWithDate:(NSDate *)date{
NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
NSInteger unitFlags = NSCalendarUnitMonth | NSCalendarUnitDay;
NSDateComponents *localeComp = [localeCalendar components:unitFlags fromDate:date];
NSString *m_str = [ChineseMonths objectAtIndex:localeComp.month-1];
NSString *d_str = [ChineseDays objectAtIndex:localeComp.day-1];
NSString *chineseCal_str =[NSString stringWithFormat: @"%@%@",m_str,d_str];
return chineseCal_str;
}
#pragma mark - 获取某天星期几
+ (NSString *)getWeekWithDate:(NSDate *)date{
NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
NSInteger weekDayFlag = [localeCalendar ordinalityOfUnit:NSCalendarUnitWeekday inUnit:NSCalendarUnitWeekOfMonth forDate:date];
NSString *weekDay_str = [WeekDays objectAtIndex:weekDayFlag];
return weekDay_str;
}
#pragma - 获取date当天的节日
+ (NSString *)getHolidays:(NSDate *)date {
NSString *todayHoliday;
//今日阳历
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc]init];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd"];
NSString *nowdate = [dateFormatter1 stringFromDate:date];
NSString *monthAndDay = [nowdate substringWithRange:NSMakeRange(5, 5)];
//农历节日
NSTimeInterval timeInterval_day = 60*60*24;
NSDate *nextDay_date = [NSDate dateWithTimeInterval:timeInterval_day sinceDate:date];
NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:
跟据某天日期获取农历或者节假日信息
最新推荐文章于 2022-08-09 16:18:21 发布