Esempio n. 1
0
        public static DateTime RiQiGetSolarDateFromChineseLunisolarDate(
            [ExcelArgument(Description = "中国农历日期")] DateTime chineseLunisolarDate,
            [ExcelArgument(Description = "当月是否是闰月")] bool isRunYue
            )

        {
            System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();

            int year      = chineseLunisolarDate.Year;
            int month     = chineseLunisolarDate.Month;
            int day       = chineseLunisolarDate.Day;
            int leapMonth = cal.GetLeapMonth(year);

            if (leapMonth > 0)
            {
                if (month > leapMonth - 1)
                {
                    month++;
                }
                else if (month == leapMonth - 1 && isRunYue)
                {
                    month++;
                }
            }

            var solarDate = cal.ToDateTime(year, month, day, 0, 0, 0, 0);

            Common.ChangeNumberFormat("yyyy-mm-dd");
            return(solarDate);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据公历获取农历日期
        /// </summary>
        /// <param name="datetime">公历日期</param>
        public static string GetChineseDateTime(DateTime datetime)
        {
            System.Globalization.ChineseLunisolarCalendar cCalendar = new System.Globalization.ChineseLunisolarCalendar();
            int lyear  = cCalendar.GetYear(datetime);
            int lmonth = cCalendar.GetMonth(datetime);
            int lday   = cCalendar.GetDayOfMonth(datetime);

            //获取闰月, 0 则表示没有闰月
            int leapMonth = cCalendar.GetLeapMonth(lyear);

            bool isleap = false;

            if (leapMonth > 0)
            {
                if (leapMonth == lmonth)
                {
                    //闰月
                    isleap = true;
                    lmonth--;
                }
                else if (lmonth > leapMonth)
                {
                    lmonth--;
                }
            }
            string ret = string.Concat(GetLunisolarYear(datetime.Year), "年", isleap ? "闰" : string.Empty, GetLunisolarMonth(lmonth), "月", GetLunisolarDay(lday));

            ret = "农历" + ret;
            return(ret);
        }
        /// <summary>
        /// 返回指定农历年,月,日,是否为闰月的农历日期时间
        /// </summary>
        /// <param name="Year"></param>
        /// <param name="Month"></param>
        /// <param name="DayOfMonth"></param>
        /// <param name="IsLeap"></param>
        public ChinaDateTime(int Year, int Month, int DayOfMonth, bool IsLeap)
        {
            if (Year >= cc.MaxSupportedDateTime.Year || Year <= cc.MinSupportedDateTime.Year)
            {
                throw new Exception("参数年份时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString() + "到" + cc.MaxSupportedDateTime.ToShortDateString());
            }

            if (Month < 1 || Month > 12)
            {
                throw new Exception("月份必须在1~12范围");
            }
            cc = new System.Globalization.ChineseLunisolarCalendar();

            if (cc.GetLeapMonth(Year) != Month && IsLeap)
            {
                throw new Exception("指定的月份不是当年的闰月");
            }
            if (cc.GetDaysInMonth(Year, IsLeap ? Month + 1 : Month) < DayOfMonth || DayOfMonth < 1)
            {
                throw new Exception("指定的月中的天数不在当前月天数有效范围");
            }
            year       = Year;
            month      = Month;
            dayOfMonth = DayOfMonth;
            isLeap     = IsLeap;
            time       = DateTime.Now;
        }
Esempio n. 4
0
        protected override void OnCreate(Bundle bundle)
        {
            // If these are not used the ToString for DateTime throws an exception in some cultures
            // For more information: https://forums.xamarin.com/discussion/42899/datetime-tostring-throws-argumentoutofrangeexception-in-thai-locale
            var c1  = new System.Globalization.ChineseLunisolarCalendar();
            var c2  = new System.Globalization.GregorianCalendar();
            var c3  = new System.Globalization.HebrewCalendar();
            var c4  = new System.Globalization.HijriCalendar();
            var c5  = new System.Globalization.JapaneseCalendar();
            var c6  = new System.Globalization.JapaneseLunisolarCalendar();
            var c7  = new System.Globalization.JulianCalendar();
            var c8  = new System.Globalization.KoreanCalendar();
            var c9  = new System.Globalization.KoreanLunisolarCalendar();
            var c10 = new System.Globalization.PersianCalendar();
            var c11 = new System.Globalization.TaiwanCalendar();
            var c12 = new System.Globalization.TaiwanLunisolarCalendar();
            var c13 = new System.Globalization.ThaiBuddhistCalendar();
            var c14 = new System.Globalization.UmAlQuraCalendar();

            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.SetVmPolicy(builder.Build());

            base.OnCreate(bundle);

            PermissionsHelper.Activity = this;

            this.SetTheme(Resource.Style.Theme_Design_Light);

            CachedImageRenderer.Init(false);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
        }
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // If these are not used the ToString for DateTime throws an exception in some cultures
            // For more information: https://forums.xamarin.com/discussion/42899/datetime-tostring-throws-argumentoutofrangeexception-in-thai-locale
            var c1  = new System.Globalization.ChineseLunisolarCalendar();
            var c2  = new System.Globalization.GregorianCalendar();
            var c3  = new System.Globalization.HebrewCalendar();
            var c4  = new System.Globalization.HijriCalendar();
            var c5  = new System.Globalization.JapaneseCalendar();
            var c6  = new System.Globalization.JapaneseLunisolarCalendar();
            var c7  = new System.Globalization.JulianCalendar();
            var c8  = new System.Globalization.KoreanCalendar();
            var c9  = new System.Globalization.KoreanLunisolarCalendar();
            var c10 = new System.Globalization.PersianCalendar();
            var c11 = new System.Globalization.TaiwanCalendar();
            var c12 = new System.Globalization.TaiwanLunisolarCalendar();
            var c13 = new System.Globalization.ThaiBuddhistCalendar();
            var c14 = new System.Globalization.UmAlQuraCalendar();

            AnalyticsHelper.Initialize(Xamarin.Forms.Device.iOS);

            global::Xamarin.Forms.Forms.Init();

            CachedImageRenderer.Init();

            LoadApplication(new App());

            UITextField.Appearance.TintColor = Xamarin.Forms.Color.FromHex("#2548D8").ToUIColor();
#if __TESTS__
            Xamarin.Calabash.Start();
#endif
            return(base.FinishedLaunching(app, options));
        }
Esempio n. 6
0
        public static string RiQiGetShengXiao(
            [ExcelArgument(Description = "公历日期")] DateTime solarDate)
        {
            System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();
            int year = cal.GetYear(solarDate);

            return("鼠牛虎兔龙蛇马羊猴鸡狗猪"[(year - 4) % 12].ToString());
        }
 public string get_ChineseZodiac(System.DateTime date)
 {
     System.Globalization.EastAsianLunisolarCalendar cc = new System.Globalization.ChineseLunisolarCalendar();
     int sexagenaryYear = cc.GetSexagenaryYear(date);
     int terrestrialBranch = cc.GetTerrestrialBranch(sexagenaryYear);
     //string[] years = "rat,ox,tiger,hare,dragon,snake,horse,sheep,monkey,fowl,dog,pig".Split(',');
     string[] years = "Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat,Monkey,Rooster,Dog,Pig".Split(',');
     return years[terrestrialBranch - 1];
 }
Esempio n. 8
0
        /// <summary>
        /// 获取指定时间的生肖属性
        /// </summary>
        /// <param name="timr">指定的时间</param>
        /// <returns></returns>
        public static string Animal_Date(DateTime timr)
        {
            System.Globalization.ChineseLunisolarCalendar chinseCaleander = //创建日历对象
                                                                            new System.Globalization.ChineseLunisolarCalendar();
            string TreeYear = "鼠牛虎兔龙蛇马羊猴鸡狗猪";                               //创建字符串对象
            int    intYear  = chinseCaleander.GetSexagenaryYear(timr);      //计算年信息

            return(TreeYear.Substring(chinseCaleander.                      //得到生肖信息
                                      GetTerrestrialBranch(intYear) - 1, 1));
        }
Esempio n. 9
0
        public string CalcChineseSign()
        {
            System.Globalization.EastAsianLunisolarCalendar cc = new System.Globalization.ChineseLunisolarCalendar();
            int sexagenaryYear    = cc.GetSexagenaryYear(Birth);
            int terrestrialBranch = cc.GetTerrestrialBranch(sexagenaryYear);

            string[] years = new string[] { "Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig" };

            return(years[terrestrialBranch - 1]);
        }
        public string get_ChineseZodiac(System.DateTime date)
        {
            System.Globalization.EastAsianLunisolarCalendar cc = new System.Globalization.ChineseLunisolarCalendar();
            int sexagenaryYear    = cc.GetSexagenaryYear(date);
            int terrestrialBranch = cc.GetTerrestrialBranch(sexagenaryYear);

            //string[] years = "rat,ox,tiger,hare,dragon,snake,horse,sheep,monkey,fowl,dog,pig".Split(',');
            string[] years = "Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat,Monkey,Rooster,Dog,Pig".Split(',');
            return(years[terrestrialBranch - 1]);
        } // End Function get_ChineseZodiac
Esempio n. 11
0
        public static string RiQiGetGanZhiYear(
            [ExcelArgument(Description = "公历日期")] DateTime solarDate)
        {
            System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();
            int year = cal.GetYear(solarDate);

            char gan = "甲乙丙丁戊己庚辛壬癸"[(year - 4) % 10];
            char zhi = "子丑寅卯辰巳午未申酉戌亥"[(year - 4) % 12];

            return(new string(new char[] { gan, zhi }));
        }
Esempio n. 12
0
        /// <summary>
        /// 获得生肖
        /// </summary>
        /// <param name="birthday"></param>
        /// <returns></returns>
        public static string GetShengXiao(DateTime birthday)
        {
            System.Globalization.ChineseLunisolarCalendar chinseCaleander = new System.Globalization.ChineseLunisolarCalendar();

            string TreeYear = "鼠牛虎兔龙蛇马羊猴鸡狗猪";

            int intYear = chinseCaleander.GetSexagenaryYear(birthday);

            string Tree = TreeYear.Substring(chinseCaleander.GetTerrestrialBranch(intYear) - 1, 1);

            return(Tree);
        }
Esempio n. 13
0
        private void btn_Get_Click(object sender, EventArgs e)
        {
            System.Globalization.ChineseLunisolarCalendar chinseCaleander =    //建立日曆物件
                                                                            new System.Globalization.ChineseLunisolarCalendar();
            string TreeYear = "鼠牛虎兔龍蛇馬羊猴雞狗豬";                                  //建立字串物件
            int    intYear  = chinseCaleander.GetSexagenaryYear(DateTime.Now); //計算年訊息
            string Tree     = TreeYear.Substring(chinseCaleander.              //得到生肖訊息
                                                 GetTerrestrialBranch(intYear) - 1, 1);

            MessageBox.Show("今年是十二生肖" + Tree + "年",//輸出生肖訊息
                            "判斷十二生肖", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }
Esempio n. 14
0
        internal string ChineseSignCalc()
        {
            var c = new System.Globalization.ChineseLunisolarCalendar();
            var y = c.GetSexagenaryYear(BirthDate.Value);
            var s = c.GetCelestialStem(y) - 1;

            return
                (",Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat,Monkey,Rooster,Dog,Pig".Split(',')[
                     c.GetTerrestrialBranch(y)]
                 + " - "
                 + "Wood,Fire,Earth,Metal,Water".Split(',')[s / 2]
                 + " - Y" + (s % 2 > 0 ? "in" : "ang"));
        }
Esempio n. 15
0
        private void btn_Get_Click(object sender, EventArgs e)
        {
            System.Globalization.ChineseLunisolarCalendar chinseCaleander =    //创建日历对象
                                                                            new System.Globalization.ChineseLunisolarCalendar();
            string TreeYear = "鼠牛虎兔龙蛇马羊猴鸡狗猪";                                  //创建字符串对象
            int    intYear  = chinseCaleander.GetSexagenaryYear(DateTime.Now); //计算年信息
            string Tree     = TreeYear.Substring(chinseCaleander.              //得到生肖信息
                                                 GetTerrestrialBranch(intYear) - 1, 1);

            MessageBox.Show("今年是十二生肖" + Tree + "年",//输出生肖信息
                            "判断十二生肖", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }
Esempio n. 16
0
        static void ChineseTest()
        {
            var dt = DateTime.Now;

            Console.WriteLine(dt);
            //中国农历
            var zhcal     = new System.Globalization.ChineseLunisolarCalendar();
            int yearIndex = zhcal.GetSexagenaryYear(dt);
            int yTG       = zhcal.GetCelestialStem(yearIndex);
            int yDZ       = zhcal.GetTerrestrialBranch(yearIndex);

            Console.WriteLine($"{_celestialStem[yTG - 1]}{_terrestrialBranch[yDZ - 1]}  {_chineseZodiac[yDZ - 1]}年  {_chineseMonth[zhcal.GetMonth(dt) - 1]}月{_chineseDay[zhcal.GetDayOfMonth(dt) - 1]}");
        }
Esempio n. 17
0
        // https://www.yourchineseastrology.com/zodiac/how-to-calculate-animal-sign.htm
        public static string GetChineseZodiac(System.DateTime date)
        {
            System.Globalization.EastAsianLunisolarCalendar cc =
                new System.Globalization.ChineseLunisolarCalendar();
            int sexagenaryYear    = cc.GetSexagenaryYear(date);
            int terrestrialBranch = cc.GetTerrestrialBranch(sexagenaryYear);

            // string[] years = "rat,ox,tiger,hare,dragon,snake,horse,sheep,monkey,fowl,dog,pig".Split(',');
            // string[] years = "Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat,Monkey,Rooster,Dog,Pig".Split(',');
            // string[] years = new string[]{ "rat", "ox", "tiger", "hare", "dragon", "snake", "horse", "sheep", "monkey", "fowl", "dog", "pig" };
            string[] years = new string[] { "Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig" };

            return(years[terrestrialBranch - 1]);
        } // End Function get_ChineseZodiac
Esempio n. 18
0
        /// <summary>
        /// 返回指定公历日期的阴历时间
        /// </summary>
        /// <param name="time"></param>
        public ChinaDateTime(DateTime time)
        {
            cc = new System.Globalization.ChineseLunisolarCalendar();

            if (time > cc.MaxSupportedDateTime || time < cc.MinSupportedDateTime)
                throw new Exception("参数日期时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString() + "到" + cc.MaxSupportedDateTime.ToShortDateString());
            year = cc.GetYear(time);
            month = cc.GetMonth(time);
            dayOfMonth = cc.GetDayOfMonth(time);
            isLeap = cc.IsLeapMonth(year, month);
            if (isLeap) month -= 1;
            this.time = time;

        }
Esempio n. 19
0
        public static System.DateTime GetChineseNewYear(System.DateTime utcYear)
        {
            System.Globalization.ChineseLunisolarCalendar chinese   = new System.Globalization.ChineseLunisolarCalendar();
            System.Globalization.GregorianCalendar        gregorian = new System.Globalization.GregorianCalendar();

            // Get Chinese New Year of current UTC date/time
            System.DateTime chineseNewYear = chinese.ToDateTime(utcYear.Year, 1, 1, 0, 0, 0, 0);

            // Convert back to Gregorian (you could just query properties of `chineseNewYear` directly,
            // but I prefer to use `GregorianCalendar` for consistency:
            int year  = gregorian.GetYear(chineseNewYear);
            int month = gregorian.GetMonth(chineseNewYear);
            int day   = gregorian.GetDayOfMonth(chineseNewYear);

            return(new System.DateTime(year, month, day));
        }
Esempio n. 20
0
        /// <summary>
        /// 将公历(阳历,西历) 转换为 农历(阴历)
        ///
        ///    DateTime dt = Convert.ToDateTime("2010-07-2 00:00:00");
        ///    MessageBox.Show(calendarSolarToChineseLunisolar(dt).ToString());
        ///
        /// </summary>
        ///

        public static DateTime calendarSolarToChineseLunisolar(DateTime SolarDateTime)
        {
            System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();

            int cYear  = cal.GetYear(SolarDateTime);
            int cMonth = cal.GetMonth(SolarDateTime);
            int cDay   = cal.GetDayOfMonth(SolarDateTime);

            DateTime dt = Convert.ToDateTime(
                Convert.ToString(cYear) + "-" +
                Convert.ToString(cMonth) + "-" +
                Convert.ToString(cDay)
                + " 00:00:00");

            return(dt);
        }
Esempio n. 21
0
        /// <summary>
        /// 返回指定公历日期的阴历时间
        /// </summary>
        /// <param name="time"></param>
        public ChinaDateTime(DateTime time)
        {
            cc = new System.Globalization.ChineseLunisolarCalendar();

            if (time > cc.MaxSupportedDateTime || time < cc.MinSupportedDateTime)
            {
                throw new Exception("参数日期时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString() + "到" + cc.MaxSupportedDateTime.ToShortDateString());
            }
            year       = cc.GetYear(time);
            month      = cc.GetMonth(time);
            dayOfMonth = cc.GetDayOfMonth(time);
            isLeap     = cc.IsLeapMonth(year, month);
            if (isLeap)
            {
                month -= 1;
            }
            this.time = time;
        }
Esempio n. 22
0
        /// 公历转为农历的函数
        /// </summary>
        /// <remarks>作者:DeltaCat</remarks>
        /// <example>网址:http://www.zu14.cn</example>
        /// <param name="solarDateTime">公历日期</param>
        /// <returns>农历的日期</returns>
        public string SolarToChineseLunisolarDate(DateTime solarDateTime)
        {
            System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();

            int year      = cal.GetYear(solarDateTime);
            int month     = cal.GetMonth(solarDateTime);
            int day       = cal.GetDayOfMonth(solarDateTime);
            int leapMonth = cal.GetLeapMonth(year);

            return(string.Format("农历{0}{1}({2})年{3}{4}月{5}{6}"
                                 , "甲乙丙丁戊己庚辛壬癸"[(year - 4) % 10]
                                 , "子丑寅卯辰巳午未申酉戌亥"[(year - 4) % 12]
                                 , "鼠牛虎兔龙蛇马羊猴鸡狗猪"[(year - 4) % 12]
                                 , month == leapMonth ? "闰" : ""
                                 , "无正二三四五六七八九十冬腊"[leapMonth > 0 && leapMonth <= month ? month - 1 : month]
                                 , "初十廿三"[day / 10]
                                 , "日一二三四五六七八九"[day % 10]
                                 ));
        }
Esempio n. 23
0
        static void Main(string[] args)
        {
            var dt = DateTime.Parse("2019/06/02");

            Console.WriteLine(dt);
            Console.WriteLine("----------------------------------");

            //日本日历
            var jpci  = new System.Globalization.CultureInfo("ja-JP");
            var jpcal = new System.Globalization.JapaneseCalendar();

            jpci.DateTimeFormat.Calendar = jpcal;
            Console.WriteLine(dt.ToString("ggyy/MM/dd", jpci));

            Console.WriteLine("----------------------------------");
            //中国农历
            var zhcal     = new System.Globalization.ChineseLunisolarCalendar();
            int yearIndex = zhcal.GetSexagenaryYear(dt);
            int yTG       = zhcal.GetCelestialStem(yearIndex);
            int yDZ       = zhcal.GetTerrestrialBranch(yearIndex);

            Console.WriteLine($"{_celestialStem[yTG-1]}{_terrestrialBranch[yDZ-1]}  {_chineseZodiac[yDZ - 1]}年  {_chineseMonth[zhcal.GetMonth(dt)-1]}月{_chineseDay[zhcal.GetDayOfMonth(dt)-1]}");
        }
Esempio n. 24
0
        /// <summary>
        /// ȡ�õ�ǰʱ���ũ������
        /// </summary>
        /// <returns></returns>
        public static string CNDate()
        {
            System.Globalization.ChineseLunisolarCalendar l = new System.Globalization.ChineseLunisolarCalendar();
            DateTime dt = DateTime.Today; //ת�����յ�����
            string[] aMonth = { "", "����", "����", "����", "����", "����", "����", "����", "����", "����", "ʮ��", "ʮһ��", "����", "����" };

            string[] a10 = { "��", "ʮ", "��ʮ", "��ʮ" };
            string[] aDigi = { "��", "һ", "��", "��", "��", "��", "��", "��", "��", "��" };
            string sYear = "", sYearArab = "", sMonth = "", sDay = "", sDay10 = "", sDay1 = "", sLuniSolarDate = "";
            int iYear, iMonth, iDay;
            iYear = l.GetYear(dt);
            iMonth = l.GetMonth(dt);
            iDay = l.GetDayOfMonth(dt);

            //Format Year
            sYearArab = iYear.ToString();
            for (int i = 0; i < sYearArab.Length; i++)
            {
                sYear += aDigi[Convert.ToInt16(sYearArab.Substring(i, 1))];
            }

            //Format Month
            int iLeapMonth = l.GetLeapMonth(iYear); //��ȡ����

            if (iLeapMonth > 0 && iMonth <= iLeapMonth)
            {
                aMonth[iLeapMonth] = "��" + aMonth[iLeapMonth - 1];
                sMonth = aMonth[l.GetMonth(dt)];
            }
            else if (iLeapMonth > 0 && iMonth > iLeapMonth)
            {
                sMonth = aMonth[l.GetMonth(dt) - 1];
            }
            else
            {
                sMonth = aMonth[l.GetMonth(dt)];
            }

            //Format Day
            sDay10 = a10[iDay / 10];
            sDay1 = aDigi[(iDay % 10)];
            sDay = sDay10 + sDay1;

            if (iDay == 10) sDay = "��ʮ";
            if (iDay == 20) sDay = "��ʮ";
            if (iDay == 30) sDay = "��ʮ";

            //Format Lunar Date
            sLuniSolarDate = sMonth + sDay;
            return sLuniSolarDate;
        }
Esempio n. 25
0
        /// <summary>
        /// 取得当前时间的农历日期
        /// </summary>
        /// <returns></returns>
        public static string CNDate()
        {
            System.Globalization.ChineseLunisolarCalendar l = new System.Globalization.ChineseLunisolarCalendar();
            DateTime dt = DateTime.Today; //转换当日的日期

            string[] aMonth = { "", "正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "腊月", "腊月" };

            string[] a10 = { "初", "十", "二十", "三十" };
            string[] aDigi = { "O", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
            string   sYear = "", sYearArab = "", sMonth = "", sDay = "", sDay10 = "", sDay1 = "", sLuniSolarDate = "";
            int      iYear, iMonth, iDay;

            iYear  = l.GetYear(dt);
            iMonth = l.GetMonth(dt);
            iDay   = l.GetDayOfMonth(dt);

            //Format Year
            sYearArab = iYear.ToString();
            for (int i = 0; i < sYearArab.Length; i++)
            {
                sYear += aDigi[Convert.ToInt16(sYearArab.Substring(i, 1))];
            }

            //Format Month
            int iLeapMonth = l.GetLeapMonth(iYear); //获取闰月

            if (iLeapMonth > 0 && iMonth <= iLeapMonth)
            {
                aMonth[iLeapMonth] = "闰" + aMonth[iLeapMonth - 1];
                sMonth             = aMonth[l.GetMonth(dt)];
            }
            else if (iLeapMonth > 0 && iMonth > iLeapMonth)
            {
                sMonth = aMonth[l.GetMonth(dt) - 1];
            }
            else
            {
                sMonth = aMonth[l.GetMonth(dt)];
            }


            //Format Day
            sDay10 = a10[iDay / 10];
            sDay1  = aDigi[(iDay % 10)];
            sDay   = sDay10 + sDay1;

            if (iDay == 10)
            {
                sDay = "初十";
            }
            if (iDay == 20)
            {
                sDay = "二十";
            }
            if (iDay == 30)
            {
                sDay = "三十";
            }

            //Format Lunar Date
            sLuniSolarDate = sMonth + sDay;
            return(sLuniSolarDate);
        }
Esempio n. 26
0
        /// <summary>
        /// 返回指定农历年,月,日,是否为闰月的农历日期时间
        /// </summary>
        /// <param name="Year"></param>
        /// <param name="Month"></param>
        /// <param name="DayOfMonth"></param>
        /// <param name="IsLeap"></param>
        public ChinaDateTime(int Year, int Month, int DayOfMonth, bool IsLeap)
        {
            if (Year >= cc.MaxSupportedDateTime.Year || Year <= cc.MinSupportedDateTime.Year)
                throw new Exception("参数年份时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString() + "到" + cc.MaxSupportedDateTime.ToShortDateString());

            if (Month < 1 || Month > 12)
                throw new Exception("月份必须在1~12范围");
            cc = new System.Globalization.ChineseLunisolarCalendar();

            if (cc.GetLeapMonth(Year) != Month && IsLeap)
                throw new Exception("指定的月份不是当年的闰月");
            if (cc.GetDaysInMonth(Year, IsLeap ? Month + 1 : Month) < DayOfMonth || DayOfMonth < 1)
                throw new Exception("指定的月中的天数不在当前月天数有效范围");
            year = Year;
            month = Month;
            dayOfMonth = DayOfMonth;
            isLeap = IsLeap;
            time = DateTime.Now;
        }