生日2星座,生日星座,public Strin
分享于 点击 44021 次 点评:93
生日2星座,生日星座,public Strin
public String getConstellation(){ String[] constellationArr = { "水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座" }; int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22 }; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String birth = "1990-10-07" if (birth != null && !"".equals(birth)) { Date date; try { date = dateFormat.parse(birth); Calendar time = Calendar.getInstance(); time.setTime(date); int month = time.get(Calendar.MONTH); int day = time.get(Calendar.DAY_OF_MONTH); if (day < constellationEdgeDay[month]) { month = month - 1; } if (month >= 0) { return constellationArr[month]; } //default to return 魔羯 return constellationArr[11]; } catch (ParseException e) { e.printStackTrace(); } } return ""; }//该片段来自于http://byrx.net
用户点评