Last active
December 24, 2015 23:29
-
-
Save LiLejia/6880188 to your computer and use it in GitHub Desktop.
从NSDate的日期获得星座,星座分个参照 http://www.chinaz.com/program/2009/1226/102350.shtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)starSign:(NSDate *)date{ | |
if(!date) | |
return @"处女座"; | |
NSString *info = @"水瓶座*0120*0219#双鱼座*0220*0320#白羊座*0321*0420#金牛座*0421*0521#双子座*0522*0621#巨蟹座*0622*0722#狮子座*0723*0823#处女座*0824*0923#天秤座*0924*1023#天蝎座*1024*1122#射手座*1123*1222#摩蝎座*1222*0119#"; | |
NSArray *array = [info componentsSeparatedByString:@"#"]; | |
NSString *starSignString = @"摩羯座"; | |
NSCalendar *calender = [NSCalendar currentCalendar]; | |
NSDateComponents *components = [calender components:(NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:date]; | |
for(NSString *infoString in array){ | |
if(!infoString||infoString.length<=1) | |
continue; | |
NSArray *detaiArray = [infoString componentsSeparatedByString:@"*"]; | |
NSString *from = [detaiArray objectAtIndex:1]; | |
int fromMonth = [[from substringFromIndex:0 length:2] intValue]; | |
int fromDay = [[from substringFromIndex:2 length:2] intValue]; | |
NSString *to = [detaiArray objectAtIndex:2]; | |
int toMonth = [[to substringFromIndex:0 length:2] intValue]; | |
int toDay = [[to substringFromIndex:2 length:2] intValue]; | |
NSString *starSine = [detaiArray objectAtIndex:0]; | |
if(components.month>=fromMonth&&components.month<=toMonth){ | |
if(components.month==fromMonth){ | |
if(components.day>=fromDay) | |
starSignString = starSine; | |
return starSignString; | |
} | |
if(components.month==toMonth){ | |
if(components.day<=toDay) | |
starSignString = starSine; | |
return starSignString; | |
} | |
} | |
} | |
return starSignString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment