ASP.NET根据日期获取星座方法!
/// <summary>返回星座
///
/// </summary>
/// <param name="date">日期</param>
/// <returns></returns>
public static string GetXinZuo(string date)
{
DateTime d;
if (DateTime.TryParse(date, out d))
{
d = DateTime.Parse(d.Month + "-" + d.Day);
if (d >= DateTime.Parse("03-21") && d <= DateTime.Parse("04-19"))
{
return "白羊座";
}
else if (d >= DateTime.Parse("04-20") && d <= DateTime.Parse("05-20"))
{
return "金牛座";
}
else if (d >= DateTime.Parse("05-21") && d <= DateTime.Parse("06-21"))
{
return "双子座";
}
else if (d >= DateTime.Parse("06-22") && d <= DateTime.Parse("07-22"))
{
return "巨蟹座";
}
else if (d >= DateTime.Parse("07-23") && d <= DateTime.Parse("08-22"))
{
return "狮子座";
}
else if (d >= DateTime.Parse("08-23") && d <= DateTime.Parse("09-22"))
{
return "处女座";
}
else if (d >= DateTime.Parse("09-23") && d <= DateTime.Parse("10-23"))
{
return "天秤座";
}
else if (d >= DateTime.Parse("10-24") && d <= DateTime.Parse("11-22"))
{
return "天蝎座";
}
else if (d >= DateTime.Parse("11-23") && d <= DateTime.Parse("12-21"))
{
return "射手座";
}
else if ((d >= DateTime.Parse("12-22") && d <= DateTime.Parse("12-31")) ||
(d >= DateTime.Parse("01-01") && d <= DateTime.Parse("01-19")))
{
return "摩羯座";
}
else if (d >= DateTime.Parse("01-20") && d <= DateTime.Parse("02-18"))
{
return "水瓶座";
}
else if (d >= DateTime.Parse("02-19") && d <= DateTime.Parse("03-20"))
{
return "双鱼座";
}
else
{
return "未知日期";
}
}
else
{
return "日期格式错误";
}
}
///
/// </summary>
/// <param name="date">日期</param>
/// <returns></returns>
public static string GetXinZuo(string date)
{
DateTime d;
if (DateTime.TryParse(date, out d))
{
d = DateTime.Parse(d.Month + "-" + d.Day);
if (d >= DateTime.Parse("03-21") && d <= DateTime.Parse("04-19"))
{
return "白羊座";
}
else if (d >= DateTime.Parse("04-20") && d <= DateTime.Parse("05-20"))
{
return "金牛座";
}
else if (d >= DateTime.Parse("05-21") && d <= DateTime.Parse("06-21"))
{
return "双子座";
}
else if (d >= DateTime.Parse("06-22") && d <= DateTime.Parse("07-22"))
{
return "巨蟹座";
}
else if (d >= DateTime.Parse("07-23") && d <= DateTime.Parse("08-22"))
{
return "狮子座";
}
else if (d >= DateTime.Parse("08-23") && d <= DateTime.Parse("09-22"))
{
return "处女座";
}
else if (d >= DateTime.Parse("09-23") && d <= DateTime.Parse("10-23"))
{
return "天秤座";
}
else if (d >= DateTime.Parse("10-24") && d <= DateTime.Parse("11-22"))
{
return "天蝎座";
}
else if (d >= DateTime.Parse("11-23") && d <= DateTime.Parse("12-21"))
{
return "射手座";
}
else if ((d >= DateTime.Parse("12-22") && d <= DateTime.Parse("12-31")) ||
(d >= DateTime.Parse("01-01") && d <= DateTime.Parse("01-19")))
{
return "摩羯座";
}
else if (d >= DateTime.Parse("01-20") && d <= DateTime.Parse("02-18"))
{
return "水瓶座";
}
else if (d >= DateTime.Parse("02-19") && d <= DateTime.Parse("03-20"))
{
return "双鱼座";
}
else
{
return "未知日期";
}
}
else
{
return "日期格式错误";
}
}
撸码:复制、粘贴,拿起键盘就是“干”!!!