IOS based on birthday get Zodiac, constellation, age algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.