Exemple #1
0
        /// <summary>
        /// 将  农历(阴历)   转换为   公历(阳历,西历)
        ///    如果传入的参数中的年份是润年,需要另外进行加上润月的天数,简单测试,但没有做过多的测试,不知是否完全正确
        ///
        ///    DateTime dt = Convert.ToDateTime("2010-05-21 00:00:00");
        ///    MessageBox.Show(calendarChineseLunisolarToSolar(dt).ToString());
        ///
        /// </summary>
        ///
        public static DateTime calendarChineseLunisolarToSolar(DateTime ChineseLunisolarDateTime)
        {
            System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();

            if (ChineseLunisolarDateTime.Year < 1902 || ChineseLunisolarDateTime.Year > 2100)
            {
                throw new Exception("只支持1902〜2100期间的农历年");
            }

            DateTime dt = cal.ToDateTime(ChineseLunisolarDateTime.Year, ChineseLunisolarDateTime.Month, ChineseLunisolarDateTime.Day, 0, 0, 0, 0);

            //检测是否含有润月
            int leapMonth = cal.GetLeapMonth(ChineseLunisolarDateTime.Year);

            int leapMonthInDays = 0;

            if (leapMonth > 0)
            {
                //有润月,则读到这个润月里面的天数
                leapMonthInDays = cal.GetDaysInMonth(ChineseLunisolarDateTime.Year, ChineseLunisolarDateTime.Month);
            }

            dt = dt.AddDays(leapMonthInDays);

            return(dt);
        }
Exemple #2
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);
        }
Exemple #3
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));
        }
 /// <summary>
 /// 获取当前农历日期的公历时间
 /// </summary>
 public DateTime ToDateTime()
 {
     return(cc.ToDateTime(year, isLeap ? month + 1 : month, dayOfMonth, time.Hour, time.Minute, time.Second, time.Millisecond));
 }