久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

C#項目獲取當前時間的農(nóng)歷時間

 alaricyyy 2015-11-20
 C#項目獲取當前時間的農(nóng)歷時間 2011-12-31 14:29:23標簽:農(nóng)歷
using System.Globalization;
    class CnCanlendar_nongli
    {
        /// <summary>
        /// 實例化一個  ChineseLunisolarCalendar     
        /// </summary>
        private static ChineseLunisolarCalendar ChineseCalendar = new ChineseLunisolarCalendar();
        /// <summary>
        /// 十天干
        /// </summary>
        private static string[] tg = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
        /// <summary>
        ///  十二地支
        ///  </summary>
        private static string[] dz = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
        /// <summary>
        /// 十二生肖
        /// </summary>
        private static string[] sx = { "鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊", "猴", "雞", "狗", "豬" };
        /// <summary>
        ///  返回農(nóng)歷天干地支年
        ///   </summary>
        ///    <param name="year">農(nóng)歷年</param>
        ///    <returns></returns>
        public static string GetLunisolarYear(int year)
        {
            if (year > 3)
            {
                int tgIndex = (year - 4) % 10;
                int dzIndex = (year - 4) % 12;
                return string.Concat(tg[tgIndex], dz[dzIndex], "[", sx[dzIndex], "]");
            }
            throw new ArgumentOutOfRangeException("無效的年份!");
        }
        /// <summary>
        /// 農(nóng)歷月
        /// </summary>
        /// <returns></returns>
        private static string[] months = { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(臘)" };
        /// <summary>
        /// 農(nóng)歷日
        /// </summary>
        private static string[] days1 = { "初", "十", "廿", "三" };
        /// <summary>
        ///  農(nóng)歷日
        /// </summary>
        private static string[] days = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
        /// <summary>
        /// 返回農(nóng)歷月
        /// </summary>
        /// <param name="month">月份</param>
        /// <returns></returns>
        public static string GetLunisolarMonth(int month)
        {
            if (month < 13 && month > 0)
            {
                return months[month - 1];
            }
            throw new ArgumentOutOfRangeException("無效的月份!");
        }
        /// <summary>
        /// 返回農(nóng)歷日
        /// </summary>
        /// <param name="day">天</param>
        /// <returns></returns>
        public static string GetLunisolarDay(int day)
        {
            if (day > 0 && day < 32)
            {
                if (day != 20 && day != 30)
                {
                    return string.Concat(days1[(day - 1) / 10], days[(day - 1) % 10]);
                }
                else
                {
                    return string.Concat(days[(day - 1) / 10], days1[1]);
                }
            }
            throw new ArgumentOutOfRangeException("無效的日!");
        }

        /// <summary>
        /// 根據(jù)公歷獲取農(nóng)歷日期
        /// </summary>
        /// <param name="datetime">公歷日期</param>
        /// <returns></returns>
        public static string GetChineseDateTime(DateTime datetime)
        {
            //農(nóng)歷的年月日
            int year = ChineseCalendar.GetYear(datetime);
            int month = ChineseCalendar.GetMonth(datetime);
            int day = ChineseCalendar.GetDayOfMonth(datetime);
            //獲取閏月,, 0 則表示沒有閏月
            int leapMonth = ChineseCalendar.GetLeapMonth(year);
            bool isleap = false;
            if (leapMonth > 0)
            {
                if (leapMonth == month)
                {
                    //閏月     
                    isleap = true;
                    month--;
                }
                else if (month > leapMonth)
                {
                    month--;
                }
            }
            return string.Concat(GetLunisolarYear(year), "年", isleap ? "閏" : string.Empty, GetLunisolarMonth(month), "月", GetLunisolarDay(day));
        }
    }

    本站是提供個人知識管理的網(wǎng)絡存儲空間,,所有內容均由用戶發(fā)布,不代表本站觀點,。請注意甄別內容中的聯(lián)系方式,、誘導購買等信息,謹防詐騙,。如發(fā)現(xiàn)有害或侵權內容,,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約