下面是根据年月日时间获取所属星座
1 /// <summary> 2 /// 根据生日过的星座 3 /// </summary> 4 /// <param name="birthday"></param> 5 /// <returns></returns> 6 public string GetAtomByDateTime(DateTime birthday) 7 { 8 string ret = "外星人啊"; 9 float birthdayF = 0.00F; 10 if(birthday.Month == 1 && birthday.Day < 20) 11 { 12 birthdayF = float.Parse(string.Format("13.{0}", birthday.Day)); 13 } 14 else 15 { 16 birthdayF = float.Parse(string.Format("{0}.{1}", birthday.Month, birthday.Day)); 17 } 18 float[] atomBound = { 1.20F, 2.19F, 3.21F, 4.20F, 5.21F, 6.22F, 7.23F, 8.23F, 9.23F, 10.24F, 11.23F, 12.22F, 13.20F }; 19 string[] atoms = { "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座" }; 20 21 for (int i = 0; i < atomBound.Length -1; i++) 22 { 23 if (atomBound[i] <= birthdayF && atomBound[i + 1] > birthdayF) 24 { 25 ret = atoms[i]; 26 break; 27 } 28 } 29 return ret; 30 }
嘻嘻
js代码
function getAstro(month, day) { var s = "魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯"; var arr = [20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22]; return s.substr(month * 2 - (day < arr[month - 1] ? 2 : 0), 2); } </script