根据生日判断星座

输入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];
    }

 

你可能感兴趣的:(判断)