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

        /// <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)));
        }

 

posted on 2013-04-08 17:28  wboweb  阅读(238)  评论(0编辑  收藏  举报

导航