获取星座
/**
* 获取星座
*
* @param month 生日 月
* @param day 生日 日
* @return 返回星座
*/
private String getHoroscopes(int month, int day) {
String[] astro = new String[]{"摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座",
"双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座"};
int[] arr = new int[]{20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22};// 两个星座分割日
int index = month;
// 所查询日期在分割日之前,索引-1,否则不变
if (day < arr[month - 1]) {
index = index - 1;
}
// 返回索引指向的星座string
return astro[index];
}
获取属相
/**
* 根据年获取属相
*
* @param year 生日 年
* @return 返回属相
*/
private String getChineseZodiac(int year) {
if (year < 1900) {
return "未知";
}
int start = 1900;
String[] years = new String[]{
"鼠", "牛", "虎", "兔",
"龙", "蛇", "马", "羊",
"猴", "鸡", "狗", "猪"
};
return years[(year - start) % years.length];
}