首页 > 解决方案 > Flutter中如何判断生肖

问题描述

我怎么能用颤振写这个?我已经快速制作了这个应用程序,现在我正在制作应用程序,这是获得十二生肖的最佳方法。谢谢你

let calendar = Calendar.current
    let d = calendar.component(.day, from: date)
    let m = calendar.component(.month, from: date)

    switch (d,m) {
    case (21...31,1),(1...19,2):
        return "aquarius"
    case (20...29,2),(1...20,3):
        return "pisces"
    case (21...31,3),(1...20,4):
        return "aries"
    case (21...30,4),(1...21,5):
        return "taurus"
    case (22...31,5),(1...21,6):
        return "gemini"
    case (22...30,6),(1...22,7):
        return "cancer"
    case (23...31,7),(1...22,8):
        return "leo"
    case (23...31,8),(1...23,9):
        return "virgo"
    case (24...30,9),(1...23,10):
        return "libra"
    case (24...31,10),(1...22,11):
        return "scorpio"
    case (23...30,11),(1...21,12):
        return "sagittarius"
    default:
        return "capricorn"
    }

标签: flutter

解决方案


想通了基本的解决方案。


String getZodicaSign(DateTime date)  {
    var days = date.day;
    var months = date.month;
   if (months == 1) {
        if (days >= 21) {
            return "Aquarius";
        }else {
            return "Capricorn";
        }
    }else if (months == 2) {
        if (days >= 20) {
            return "Picis";
        }else {
            return "Aquarius";
        }
    }else if (months == 3) {
        if (days >= 21) {
            return "Aries";
        }else {
            return "Pisces";
        }
    }else if (months == 4) {
        if (days >= 21) {
            return "Taurus";
        }else {
            return "Aries";
        }
    }else if (months == 5) {
        if (days >= 22) {
            return "Gemini";
        }else {
            return "Taurus";
        }
    }else if (months == 6) {
        if (days >= 22) {
            return "Cancer";
        }else {
            return "Gemini";
        }
    }else if (months == 7) {
        if (days >= 23) {
            return "Leo";
        }else {
            return "Cancer";
        }
    }else if (months == 8) {
        if (days >= 23) {
            return "Virgo";
        }else {
            return "Leo";
        }
    }else if (months == 9) {
        if (days >= 24) {
            return "Libra";
        }else {
            return "Virgo";
        }
    }else if (months == 10) {
        if (days >= 24) {
            return "Scorpio";
        }else {
            return "Libra";
        }
    }else if (months == 11) {
        if (days >= 23) {
            return "Sagittarius";
        }else {
            return "Scorpio";
        }
    }else if (months == 12) {
        if (days >= 22) {
            return "Capricorn";
        }else {
            return "Sagittarius";
        }
    }
    return "";
  }

推荐阅读