According to the user's birthday, get the corresponding age, Constellation and Zodiac. Some projects may be used, posted to share.
Get the age, this is simple:
-(void) Getagewith: (nsdate*) birthday{ // calendar Nscalendar *gregorian = [[Nscalendar alloc] Initwithcalendaridentifier:nscalendaridentifiergregorian]; = nscalendarunityear; *components = [Gregorian components:unitflags fromdate:birthday todate:[nsdate Date] Options:0] ; = [NSString stringWithFormat:@ "%ld years old ", [Components year]+1];}
Get a constellation based on the day of the month:
//get the constellation algorithm-(NSString *) Getastrowithmonth: (Nsinteger) M Day: (Nsinteger) d{nsstring*astrostring =@"capricorn Aquarius double milt goat Taurus Gemini giant crab lion Virgin libra scorpio shooter Capricorn"; NSString*astroformat =@"102123444543"; NSString*result; if(m<1|| M> A|| d<1|| D> to){ return @"wrong date format!"; } if(m==2&& d> in) { return @"wrong date format !"; }Else if(m==4|| m==6|| m==9|| m== One) { if(d> -) { return @"Bad date format!!!"; }} result=[nsstring stringWithFormat:@"%@", [Astrostring Substringwithrange:nsmakerange (m*2-(d < [[Astroformat Substringwithrange:nsmakerange (M-1),1)] [Intvalue]-(- +))*2,2)]]; return[Result stringbyappendingstring:@"seat"]; }
Get the Zodiac According to the year:
-(NSString *) Getzodiacwithyear: (Nsinteger) y{if(Y <0) { return @"Bad date format!!!"; } nsstring*zodiacstring =@"Mouse cow tiger rabbit dragon snake horse sheep monkey chicken Dog pig"; Nsrange Range= Nsmakerange ((y+9)% A-1,1); NSString* result =[zodiacstring Substringwithrange:range]; return[Result stringbyappendingstring:@"years"]; }
Wrote a demo, need to go here to download: https://github.com/wangdachui/WTZodiacSigns
IOS based on birthday get Zodiac, constellation, age algorithm