您的位置:首页 > 其它

公历获取生肖和公历获取农历

2013-04-08 17:28 288 查看
/// <summary>
/// 根据月份和日期计算星座
/// </summary>
/// <param name="month"></param>
/// <param name="day"></param>
/// <returns></returns>
public string GetXingZuoByMonthAndDay(int month, int day)
{
string s = "魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯";
int[] arr = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22 };
return s.Substring(month * 2 - (day < arr[month - 1] ? 2 : 0), 2);
}

///<summary>
/// 根据公历获取农历日期
///</summary>
///<param name="datetime">公历日期</param>
///<returns>农历日期</returns>
public static DateTime GetChineseDateTime(DateTime datetime)
{
System.Globalization.ChineseLunisolarCalendar cd = new System.Globalization.ChineseLunisolarCalendar();
int year = cd.GetYear(datetime);
int month = cd.GetMonth(datetime);
int leapMonth = cd.GetLeapMonth(year);
if (leapMonth > 0 && leapMonth <= month)
month--;
return DateTime.Parse(string.Format("{0}-{1}-{2} {3}:{4}:{5}", year, month, cd.GetDayOfMonth(datetime), cd.GetHour(datetime), cd.GetMinute(datetime), cd.GetSecond(datetime)));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: