`
Iam42
  • 浏览: 272967 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

根据生日判断星座

    博客分类:
  • Java
阅读更多

输入String(“yyyy-mm-dd”)

输出String(星座)

public static String getConstellation(String birthday) {

        String[] constellationArr = { "水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座",
                "天蝎座", "射手座", "魔羯座"};

        int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22 };

        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date birthDay = formatDate.parse(birthday);
            int month = birthDay.getMonth();
            int day = birthDay.getDay();
            if (day < constellationEdgeDay[month]) {
                month = month - 1;
            }
            if (month >= 0) {
                return constellationArr[month];
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return constellationArr[11];
    }

 

0
4
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics