public string GetAtomFromBirthday(DateTime birthday)
{
float birthdayF = 0.00F; if (birthday.Month == 1 && birthday.Day < 20)
{
birthdayF = float.Parse(string.Format("13.{0}", birthday.Day));
}
else
{
birthdayF = float.Parse(string.Format("{0}.{1}", birthday.Month, birthday.Day));
}
float[] atomBound = { 1.20F, 2.20F, 3.21F, 4.21F, 5.21F, 6.22F, 7.23F, 8.23F, 9.23F, 10.23F, 11.21F, 12.22F, 13.20F }; string[] atoms = { "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座" };
string ret = "日期错误";
for (int i = 0; i < atomBound.Length - 1; i++)
{
if (atomBound[i] <= birthdayF && atomBound[i + 1] > birthdayF)
{
ret = atoms[i];
break;
}
}
return ret;
}
在这一方法中,按理说1.6号为摩羯座,可是按照这个方法,他却是执行了string ret = "日期错误";
之一句,主要是红色字体处不太明白。。能否解释一下,
------解决方案--------------------------------------------------------
float[] atomBound 里面的是星座结尾日期的格式
星座 日期(公历) 英文名
魔羯座 (12/22 - 1/19) Capricorn
水瓶座 (1/20 - 2/18) Aquarius
双鱼座 (2/19 - 3/20) Pisces
牡羊座 (3/21 - 4/20) Aries
金牛座 (4/21 - 5/20) Taurus
双子座 (5/21 - 6/21) Gemini
巨蟹座 (6/22 - 7/22) Cancer
狮子座 (7/23 - 8/22) Leo
处女座 (8/23 - 9/22) Virgo
天秤座 (9/23 - 10/22) Libra
天蝎座 (10/23 - 11/21) Scorpio
射手座 (11/22 - 12/21) Sagittarius
你帖的不全。
http://www.cnblogs.com/shilly/archive/2010/11/15/1877418
------解决方案--------------------------------------------------------
/// <summary>
/// 根据生日获取星座
/// </summary>
/// <param name="birthday"></param>